.net

Using System.Windows.Forms.Timer.Start()/Stop() versus Enabled = true/false

Suppose we are using System.Windows.Forms.Timer in a .Net application, Is there any meaningful difference between using the Start() and Stop() methods on the timer, versus using the Enabled property? For example, if we wish to pause a timer while we do some processing, we could do: myTimer.Stop(); // Do something interesting here. myTi...

How would I sort a list of files by name to match how Windows Explorer displays them?

Let's say I've sorted a list of files in Explorer by name, like so: 2009-06-02-4.0.9.txt 2009-06-02-4.0.10.txt 2009-06-02-4.0.11.txt 2009-06-02-4.0.12.txt I have a FileInfo Comparer that sorts an array of FileInfo objects by name: class FileInfoComparer : IComparer<FileInfo> { public int Compare(FileInfo x, FileInfo y) { ...

Marshal Unmanaged struct to managed code using c#

Hi experts, I need to process the bytes[] when i get from external application. The external application is also done in c# and they send the bytes thru UDP. They are sending the bytes converted from struct which is stated below : public struct DISPATCH_MESSAGE { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public c...

Windows Services open source framework

I was listening to a podcast a while back on an Open Source project. I can't remember what the project was called, but the guys doing it said they'd split out their Windows Service support into a separate Open Source project. Like I say, I can't remember the project or what they've called the break-out project. All I remember is that ...

Persist WPF Control in *.settings File

Is it possible to persist a WPF Control, or any other non-trivial object to a *.settings file in a .NET application? I figured this would be easy since the *.settings file allows me to specify an atrbitrary type for each individual settings, unfortunately, it does not appear to be functioning for me. What I am trying to do is to persist...

Trace Filtering

How do I go about using filtering on the built in trace listeners, such as System.Diagnostics.DefaultTraceListener and System.Diagnostics.TextWriterTraceListener? I don't want to have to override write methods and explicitly check the filtering, but I can find no way to attach a level to trace information? ...

IDisposable, Finalizers and the definition of an unmanaged resource

I'm trying to make sure that my understanding of IDisposable is correct and there's something I'm still not quite sure on. IDisposable seems to serve two purpose. To provide a convention to "shut down" a managed object on demand. To provide a convention to free "unmanaged resources" held by a managed object. My confusion comes from ...

Can I pass in T.Property? Also, ideas for improving this method?

Or possibly there is a better way. I am building a dynamic query builder for NHibernate, we don't want to put HQL directly into the application, we want it as ORM agnostic as possible. It looks like this currently: public override IEnumerable<T> SelectQuery(Dictionary<string, string> dictionary) { string t = Convert.ToSt...

How to send files over tcp with TcpListener/Client? SocketException problem

I'm developing a simple application to send files over TCP using the TCPListener and TCPClient classes. Here's the code that sends the file. Stop is a volatile boolean which helps stopping the process at any time and WRITE_BUFFER_SIZE might be changed in runtime (another volatile) while (remaining > 0 && !stop) { DateTime current = D...

SQLCLR Community Extensions or common library

Having just finished writing a Regex replacement and match function and tvf for SQLCLR for the fifth time, I sat and pondered whether there was a set of common community extensions for SQLCLR for the most common things you want in a database but are never provided. Powershell for example has an excellent set of community extensions that...

C# MethodInfo getReturnType

I created an instance of MethodInfo: MethodInfo theMethod = typeof(Reciever).GetMethod("methodName", parameterTypes); Now I want to know if theMethod's return type is void. How? ...

Is there a way to map an enumeration to another enumeration in C#.NET 3.5?

I'm trying to set up an enumeration that maps certain project-specific values to the standard System.Drawing.Color enum. Here's the idea of what I'd like to do: public enum SessionColors { Highlights = Color.HotPink, Overlays = Color.LightBlue, Redaction = Color.Black } The goal is to have it so I can use Session...

.NET 2.0 compiled app fails on machine without .NET 3.5 runtime

Hi I have compiled a NET 2.0 application using C# 2005 Express on a machine that also contains VS 2008 Express. When I run the app on a machine with .NET 2.0 SP1 runtime only the application doesn't execute and raises an error about sending report to Microsoft etc. I have the impression that the compiler silently referenced certain 3.5 ...

Why DateTime.TryParse returning false when given a real year string?

In the code below I am giving the function a sTransactionDate="1999" and I am trying to covert it to a date x/x/1999. DateTime dTransactionDate = new DateTime(); if(DateTime.TryParse(sTransactionDate, out dTransactionDate)) { //Happy }else { //Sad } if the string is "1999" it will always end up in sad. Any ideas? ...

Dos based printing using C#.net

i m using Dotmatrix printer EPSON for printing the reports, and i need the of how to print the reports without using crystalReport and print dialog, i.e. i want the code for DOS based printing in C#.net......... ...

Winforms ComboBox Databind with DropDownStyle=Dropdown

Winforms / .Net 3.5 I am using a combobox with the dropdownstyle set to dropdown (allows users to enter data). The problem I am having is with how to setup the combobox so it updates my bindingsource with values from the list and also when a user enters data. For example the combobox may contain the following values: "Red", "White",...

Get next autoincrement value for datatable column?

I have a datatable with an AutoIncrement column. How can I get the next increment (-1,-2,-3,...) for the column without adding a new row? ...

DataContext reusing connection

Hi, this is a simple question that you might find out if you have been in this situation before: Imagine that I have a loop and inside it I create an instance of a DataContext and I perform some queries to the database. The question is... Is the DataContext opening a Connection only the first time and reusing it or a new connection to ...

Locking on several methods only if a thread is in a certain method

I have a class (simplified example) like : public class SomeCollection : ICloneable { public void Add(Item item) { /* ... */ } public void Remove(Item item) { /* ... */ } public Item Get(Key key) { /* ... */ } /* ... */ public object Clone() { /* ... */ } } I need that when a thread enters Clone() no other ...

Can you Create Your Own Default T where T is your own class

lets say I have the following public class A { private string _someField; public string SomeField { get { return _someField; } } } For some reason I am checking the default of this class and I would like to set the default for a class, just like a default of type int is 0, I would like in the above class for my default of Som...