.net

C# Nth Root of small number precision problem

When I try to take the N th root of a small number using C# I get a wrong number. For example when I try to take the 3rd root of 1.07, I get 1, which is clearly not true. Here is the exact code I am using to get the 3rd root. MessageBox.Show(Math.Pow(1.07,(1/3)).toString()); Can anyone tell me how to solve this problem. I would gue...

Debuging CUDA kernels called from .NET code in VS2008, emulation mode

CUDA has an option to compile code in emulation mode, which is supported in the .rules file they provide. I have C# .NET 3.5 SP1 code that calls a native dll, using DllImport, the native dll is compiled via VS2008 using nvcc and its function is to transfer memory from and to CUDA and to invoke CUDA kernels. When the CUDA kernels are co...

How to use AverageTimer32 and AverageBase performance counters with System.Diagnostics.Stopwatch?

When I execute the following program and look at the performance counter the results don't make sense to me. The average value is zero and the min/max values are ~0.4 when I would expect ~0.1 or ~100. What is my problem? Code class Program { const string CategoryName = "____Test Category"; const string CounterName = "Average ...

Why do i need to wrap this code in a cast to short?

If i have some code like the following: short myShortA = 54; short myShortB = 12; short myShortC = (short)(myShortA - myShortB); Both operands are shorts and it's going into a short so why do i have to cast it? ...

How to write a class library that will work on .NET 3.5 compact framework AND regular framework?

How do I write a .NET class library that I can recompile for either the regular .NET 3.5 Framework, or the .NET 3.5 Compact Framework? ...

Automatically Calculated Properties in Linq 2 Sql Entities?

Let's say I have a table in my database called Orders that has the following columns: OrderId OrderDate CancelDate ShipDate LastActionDate I want LastActionDate to always be the latest date of OrderDate, CancelDate, and ShipDate. What's the best way to accomplish this? Is there a way to handle the OnChanged event of those three dates...

Windbg symbol load issue

Hello everyone, I am using Windbg to load a crash dump from managed code (C#, a console application built for Any CPU). I am debugging on x64 platform. I have put the related pdb file into symbol path. But when I use lm command to see load models, the symbol of the console exe application can not be loaded. I have tried to execute .relo...

General C# + ASP.net + Mono questions.

I recently installed the Mono Framework, .net 3.5 f/w and MonoDevelop (hint: I'm trying to switch over from PHP to C#3 + .net) Even though the Mono installer states that it has installed XSP2 (I can start XSP independently from the context menu), MonoDevelop says that it cannot find XSP2. Bonus Q1: When you have an asp.net app, what are ...

C# VS Express: "This method is reserved for future use" - what does it mean?

I want to use method Stream.Flush but its documentation shows that message. What does it mean? EDIT: I have not found any solution in the MSDN thread. My problem is that sometimes sending a message and client disconnecting causes the message doesn't appear. So I would need to flush the stream or socket in the OnDisconnecing event. ...

Easiest way to split a string on newlines in .net?

I need to split a string into newlines in .NET and the only way i know of to split strings is with the Split method. However that will not allow me to (easily) split on a newline, so what is the best way to do it? ...

Several unusual errors when attempting to convert a string[] to a Dictionary<short, string>

I have the following code that splits a string on newlines and converts it to a Dictionary for further processing: string[] splitProgram = program.Split(Environment.NewLine.ToCharArray()); short i = 0; Dictionary<short, string> programDictionary = splitProgram.ToDictionary<short, string>((value) => i++); What's...

Strange GDI+ behaviour.

I have made a method to CompressImageSize according to Image quality. The code for it is public static Image CompressImage(string imagePath, long quality) { Image srcImg = LoadImage(imagePath); //Image srcImg = Image.FromFile(imagePath); EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new ...

Restricting system resources to .NET application

I am maintaining a managed Windows Service project which basically invoke/run the (managed) jobs (IJob implementations from different sub-teams) at scheduled time. There are few jobs which occasionally stall the system resources. While waiting for my sub-teams to debug/fix their jobs, is there any way that I can somehow control in my p...

asp http POST Read Data

I am POSTING some data from an IPhone application want want to be able to read this data from the server. I have never created a http post server before and i am unsure which is the best way to read this data. This is the IPhone Code posting the data: /* turning the image into a NSData object getting the image back out of the UIIma...

Stuck trying to get Log4Net to work with Dependency Injection.

Hi folks, I've got a simple winform test app i'm using to try some Log4Net Dependency Injection stuff. I've made a simple interface in my Services project :- public interface ILogging { void Debug(string message); // snip the other's. } Then my concrete type will be using Log4Net... public class Log4NetLogging : ILogging {...

Switch compilation between compact and full .net framework?

Does anyone know how to switch a compilation of a library project on visual studio, so I can compile for compact framework and full .Net framework? ...

How to Save a setting for All users under Vista

I need to save a setting which is then available to all users of the application on the given machine. It needs to work on Vista/Win 7, and the application won’t be started as administrator. Can’t Save to program directory as the Program Files folder is protected on Vista Can’t save to HKEY_LOCAL_MACHINE as that’s protected too Can’t s...

Setting a Bitmap in Windows 7 thumbnail preview (C#)

Hello, I am currently using the Windows 7 API Code pack for an application I am coding in C#. Currently, I understand how to draw part of the Window region or a control into the thumbnail preview: TaskbarManager.Instance.TabbedThumbnail.SetThumbnailClip((new WindowInteropHelper(this)).Handle, new System.Drawing.Rectangle((int)v.X, (in...

Entities to DTO - Entity framework

Please review my code. For every my Entity i've created a service class, where i put all the access methods for this entity.This method are doing the transformation from the Entities to my DTO classes. This methods are called from the Web layer or a bussines method. Am I doing this righth? Or should I do it differently ? The service me...

Extensions library in C#

Hello everybody. I am looking for a good Extensions library (library with a great number of extensions methods) in C# for standard type. I have found some libraries on Codeplex, but they are considered to be very weak by me. Edit: I need a library which implements different mathematical functions for different (more the better) purposes...