.net

Coding/Designing a generic thread-safe limiter (i.e. limit the execution of X() to Y many times per second)

I'm planning to design a class to limit the execution of a function to given amount within the specified time, for example: Process max. 5 files in 1 second It should be thread-safe and performance hit should be minimal. How would you design such a class? I've got couple of ideas but none of them seemed right to me. Is there any ...

Problem in getting MAC address of the remote server using SendARP

Actually i want MAC address of the remote server so i am using SendARP method. But problem is that it is returning "" or "00-00-00-00-00-00". Actually in my network some PC's having two IP addresses.I think server also having the two IPs. For some PC in the same network my program works fine, only for 2-3 machine its giving this kind o...

In .NET, How to obtain the target of a symbolic link (or Reparse Point)?

In .NET, I think I can determine if a file is a symbolic link by calling System.IO.File.GetAttributes(), and checking for the ReparsePoint bit. like so: var a = System.IO.File.GetAttributes(fileName); if ((a & FileAttributes.ReparsePoint) != 0) { // it's a symlink } How can I obtain the target of the symbolic link, in this case?...

Override the neutral language of a specific resource file within an assembly

I have an assembly that contains several resource files. Most of them have the neutral language 'nl' (Dutch, specified on the assembly as the neutral language), so I don't specify the 'nl' in their filenames. However, I'm putting strings in the English language in some other resource files (they are internal error messages) and I will ...

BitBlt code not working

I'm trying to use this code to draw a Bitmap directly onto a PictureBox: Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp"); Graphics grDest = Graphics.FromHwnd(pictureBox1.Handle); Graphics grSrc = Graphics.FromImage(bmp); IntPtr hdcDest = grDest.GetHdc(); IntPtr hdcSrc = grSrc.GetHdc(); BitBlt(hdcDest, 0, 0, pictu...

Memory debugger for mixed-mode C++ applications

I have to maintain a large C++ mixed-mode application (VC++ 2005, CLR-support: /clr:oldsyntax). I suspect the program has a number of memory leaks but it's hard to find them manually. For native C++ applications we use Purify (and Valgrind on Linux). Unfortunately Purify does not support mixed mode assemblies. Anybody here knows a dece...

Collaborative editing for .NET development - what are the possibilities

What are the best options for real-time collaborative editing for .NET development? (C#,VB.NET, ASP.NET - not Mono unless it is the best way to get collaboration) 1) Anything possible with visual studio? 2) Collaborative editors? I know Eclipse has real-time collaboration, but I don't know how far you can combine it with .NET support....

How to handle exceptions from a BackgroundWorker thread?

In a WPF app I have a sheduled database access task, periodically run by a timer and this task have been executed in a BackgroundWorker thread. When connection attempt failed I raise an exception by try_catch construction and I want to update a Status Bar text in a UI thread. Is there some prebuild event construction in a BackgroundWo...

VB.Net - opening a file which may be local or remote (via http)

Hi all, I wonder if someone can help me; In PHP you can use fopen(Path) to read from a file. The Path can be either a local file (in the usual formats /etc/file or c:\file.txt) OR it can be a URL in which case PHP will open a http connection and read from the remote location I'd like to achieve the same in VB.Net. I'm not aware of any...

Can a class inherit from LambdaExpression in .NET? Or is this not recommended?

Consider the following code (C# 4.0): public class Foo : LambdaExpression { } This throws the following design-time error: Foo does not implement inherited abstract member System.Linq.Expressions.LambdaExpression.Accept(System.Linq.Expressions.Compiler.StackSpiller) There's absolutely no problem with public class Foo : Expression { }...

Make an operation asynchronous

I have a third party ActiveX that represents a video camera. (AcxCamera myCam;) I connect this camera to a videostream via the Connect method. (myCam.Connect(url);) It's to note that AcxCamera is an object inherited from the third party Acx, so I can "control" the Connect method. Now, I have some cameras that should be started synchro...

C#.net Mobile Application: SDF to SQL Server data sync

I have created a sdf database in a mobile application. Now I want to synchronize that database to a sql server database. How it is possible? Please help......... ...

What is the fastest way to initialize all elements in an array to NaN?

In C# .NET, what is the fastest way to initialize an array of doubles to NaN? Here is how I am presently initializing an array with many elements. int length = array.Length; for(int i = 0; i < length; i++) { array[i] = double.NaN; } Is there a faster way? ...

Make custom string encoder .net

I know .net supports base64 encoding of byte arrays. But i thought that i could save even more space if use a higher number of characters. I read somewhere that Unicode supports thousands of different characters so why not use base1024 encoding for example? And if this is possible can you give some guidelines on how to implement it. Tha...

Invoices and Bills in single table?

If i have bills (from vendors), and invoices (to customers), would it be better to keep them separate (in two tables), or in a single table? What about vendors / customers? These are all relational-inheritance problems, can you give me some best practices regarding this? ...

How long is the delay between Control.Invoke() and the calling of its Delegate?

I have a code engine that plays long WAV files by playing smaller chunks in succession using the waveOutOpen and waveOutWrite API methods. In order to update my UI as the file plays, from the callback function as each buffer completes playing I Invoke a separate thread (because you want to do as little as possible inside the callback fu...

Other ways to resize image than Graphics.DrawImage

Don't ask me why but i can't use this method because I need to create 2 image objects to make it work. I want to be able to resize a single Image object without needing to create another one. Is this possible and how? ...

.Net Regex to parse specific JSON format

I'm writing a little web service which generates SO/SF/SU/MSO user flair in the form of an image with various "themes". I find this preferable to using the HTML/JS solutions offered by SO as it's more flexible and also works better in forum signatures. I'm retrieving the data using the apparently unofficial API (More info here). I can h...

Bug in the File.ReadLines(..) method of the .net framework 4.0

This code : IEnumerable<string> lines = File.ReadLines("file path"); foreach (var line in lines) { Console.WriteLine(line); } foreach (var line in lines) { Console.WriteLine(line); } throws an ObjectDisposedException : {"Cannot read from a closed TextReader."} if the second foreach is executed. It seems that the iterator ...

Not sure how to use Dependency Injection + Repository Pattern + Unit Of Work Pattern with a WinForm application.

(apologies for the Wall Of Text... :) ) Summary Using Dependency Injection with my Winfor application is creating a large number of Repository Context's. I'm not sure if the way i'm using this is right or wrong, or what the common practice is. Details In the last 6 odd months, I've been making ASP.NET MVC applications that impliment...