.net

Where is UdpClient.CancelReceive?

I'm implementing a simple local-network discovery protocol, so I call UdpClient.Send and then UdpClient.BeginReceive. In case more than one response is pending, I call UdpClient.BeginReceive at the end of the callback. Something like this: UdpClient client = new UdpClient(AddressFamily.InterNetwork); client.EnableBroadcast = true; clien...

Best mechanism to implement an IPC Bus in .NET?

I have several apps that want to communicate LOCALLY via a data bus. Ideally: They talk and listen whenever they come online There will not be an "owner" of this communication method. No extra components to install (ie. Message Queues) It would be nice if there were no ports to require open What do you think is the best technology...

Timespan formatting

How do you elegantly format a timespan to say example "1 hour 10 minutes" when you have declared it as : TimeSpan t = new TimeSpan(0, 70, 0); ? I am of course aware that you could do some simple maths for this, but I was kinda hoping that there is something in .NET to handle this for me - for more complicated scenarios Duplicate of ...

Linq and the Equality Operator: Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object'

I'm trying to override the equality (==) operator in C# to handle comparing any type to a custom type (the custom type is really a wrapper/box around null). So I have this: internal sealed class Nothing { public override bool Equals(object obj) { if (obj == null || obj is Nothing) return true; else return false; } public...

Selecting resource file with GetGlobalResourceObject, reading against current culture

Hi, I'm using GetGlobalResourceObject to localise the language on a website after setting CurrentUICulture depending on each users settings. I am also creating an email using text retrieved via GetGlobalResourceObject which is sent to another user. Is it possible to select the language file used by GetGlobalResourceObject so that the ...

C# Generic new() constructor problem

I'm trying to create a new object of type T via its constructor when adding to the list. I'm getting a compile error: The correct error message is: 'T': cannot provide arguments when creating an instance of a variable But it does! Any ideas? public static string GetAllItems<T>(...) where T : new() { ... List<T> tabListItems = ne...

How do I limit the number of decimal places shown in a ZedGraph Y Scale?

I am using ZedGraph's master pane to display two graphs that have synchronized X axes. I am running into a problem when I zoom in on one of the graphs. As I zoom in, the Y axis will show an increasing number of decimal places, eventually causing the zoomed-in graph to be narrower than the other graph, preventing their X axes from lining...

How to export Excel worksheets into new workbooks

I have a bunch of Excel workbooks that contain multiple worksheets. I want to loop through each workbook and export each worksheet into it's own new workbook. I want one worksheet in each new workbook. Here's what I've got so far: Sub ExportWorksheet(ByVal worksheet As Excel.Worksheet, ByVal filePath As String) Dim xlApp As Ex...

Matrix Library for .NET

I'm looking for a good (well-tested, fully-featured, and ideally with a nice interface) matrix library for .NET/C#. My main requirements here are only that it should be free (I don't particularly care whether it's open-source in this case) and preferably support sparse matrix operations. The obligatory requirements are all the basic oper...

.NET Windows control for editing XML/XSL?

Apologies if this has been asked before. Had a quick search and there's nothing that answers my question 100%. I've got some XSL stored in the database which I want the user to be able to edit within my .NET Windows application. I could just stick it into a multi-line textbox but then I don't get anything like auto-indent, colour-coding...

How would you refactor this smelly code? (Logging, Copy and Paste, .Net 3.5)

I've got code like this: Logger logger = new Logger(); System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); logger.LogInformation("Calling SomeObject.SomeMethod at " + DateTime.Now.ToString()); stopWatch.Start(); // This is the method I'm interested in. SomeResponse response = someObject.SomeMethod(someParam); st...

VB.NET WithEvents keyword behavior - VB.NET compiler restriction?

I'm working on becoming as familiar with C# as I am with VB.NET (the language used at my workplace). One of the best things about the learning process is that by learning about the other language you tend to learn more about your primary language--little questions like this pop up: According to the sources I've found, and past experien...

The proper way of raising events in the .NET framework

Currently "Avoid checking for null event handlers" is at the top of the answers to the post titled Hidden Features of C# and it contains severely misleading information. While I understand that Stack Overflow is a "democracy" and the answer rose to the top by virtue of public voting, I feel that a lot of people that up-voted the answer ...

Urgent Help with decompression in c#

Hi I have some delphi code that did this needs to be re coded in c#: procedure TDocSearchX.Decompress; var BlobStream:TBlobStream; DecompressionStream:TDecompressionStream; FileStream:TFileStream; Buffer:array[0..2047] of byte; count:integer; begin BlobStream:=TBlobStream.Create(DocQueryDATA,bmRead); DecompressionStream:=TDecom...

DataRelation Insert and ForeignKey

Guys, I have a winforms application with two DataGridViews displaying a master-detail relationship from my Person and Address tables. Person table has a PersonID field that is auto-incrementing primary key. Address has a PersonID field that is the FK. I fill my DataTables with DataAdapter and set Person.PersonID column's AutoIncrement...

Threading and lambda expressions

What is the difference between the two piecees of code below. will there be any issues using the second one. Scenario 1 private void Log(Exception e) { ThreadPool.QueueUserWorkItem(new WaitCallback(Log), e); } private void Log(object obj) { Exception e = (Exception)obj; Logger.Log(e); } Scenario 2 private void Log(Excep...

How do I use reflection to determine the nested type of an array?

I have an instance of System.Type, for which "IsArray" returns true. How can I determine the "nested type" of the array type? i.e. Type GetArrayType(Type t) { if(t.IsArray) { // What to put here? } throw new Exception("Type is not an array"); } Assert.That(GetArrayType(typeof(string[])), Iz.EqualTo(typeof(str...

PowerShell, Extension Methods, and Monkey Patching

Is it possible to write extension method in PowerShell? or to bolt a new method on top of an existing type like [string] live at runtime? ...

XML HTTP POST integration in .NET

I'm working on a .NET project that integrates with an external company. This company will be sending us XML messages via HTTP POST (raw XML, not SOAP). There are basically three different types of XML messages they will be sending us, which all have their own XSDs. There is no inheritance hierarchy between these XSDs, they are all bas...

read only list with automatic properties

is there a way to do this with automatic properties ? private IList<string> List; public IList<String> list { get { return List.ToList().AsReadOnly(); } set { List = value; } } ...