.net

"A reference to a volatile field will not be treated as volatile" implications

The following code using System.Threading; class Test { volatile int counter = 0; public void Increment() { Interlocked.Increment(ref counter); } } Raises the following compiler warning: "A reference to a volatile field will not be treated as volatile" Am I doing something wrong here to raise this warning? Why...

Embedded flash video: works locally, but not on staging server

I was able to embed a video that auto plays on my local machine. When I upload my solution onto my staging server I get nothing. It's weird, everything is the same in the code. I am running Vista on my local machine and Windows Server 2003 on my server. Does someone with a little more experience in this feel like pointing me in the...

How to properly and completely close/reset a TcpClient connection?

Hi, What is the correct way to close or reset a TcpClient connection? We have software that communicates with hardware but sometimes something goes wrong and we are no longer to communicate with it, until we restart the software. I have tried forcing TcpClient.Close() and even setting it to null but that doesn't work. Only a complete ...

Use smo to rename datafiles

How can I use SMO to rename the physical .mdf .ndf .ldf files. This article was helpful but I need to use C# SMO Objects. Using the SMO Server Object I can retrieve the database, then Get Access to the DataFile objects. Per this link. These have a Rename, however after rename, nothing changes. ...

silverlight: showing/hiding user controls

My silverlight app takes the user through a sort of wizard-like process, so for each screen in the wizard I've created a seperate user control. Then in my main user control (applications RootVisual) I just show/hide each user control when needed. That means that every user control is instantiated at once, is it possible to only have o...

C# Equivalent of SQL Server 2005 DataTypes

For the following SQL Server 2005 datatypes, what would be the corresponding datatype in C#? Exact Numerics bigint numeric bit smallint decimal smallmoney int tinyint money Approximate Numerics float real Date and Time date datetimeoffset datetime2 smalldatetime datetime time Character Strings char varchar text Unico...

silverlight: How to set attached properties Programmatically

Suppose I have a grid with some row definitions, and a child control in that grid. How would I go about setting the Grid.Row property of the child control programatically? ...

Connection Pooling Not working in .Net SQL Server 2008

I'm testing out my application with the hopes of migrating to SQL Server 2008 (From 200). In the SQL Server profiler, I'm seeing Audit Login SQL:BatchStarting SELECT ..... SQL:BatchCompleted SELECT ..... Audit Logout for every single query that is being run. From what I can tell, this means t...

Using Debug Thirdparty DLLs in Production

I want to use Rhino Tools in an application (for the Binsor support). There isn't a binary release so I'm downloading the source and compiling it. It compiles the debug binaries no problem, but the release build fails. The app that I'm developing will be deployed with release binaries, but will have to reference the debug build of Rhino...

Sql Parameter Collection

I have 5 parameters and I want to send them to the method: public static SqlCommand getCommand(string procedure, SqlParameter[] parameter) { Sqlcommand cmd; return cmd } Can I send these paramters at one time like this? SqlParameterCollection prm; prm.Add(p1); prm.Add(p2); prm.Add(p3); prm.Add(p4); prm.Add(p5); sqlcommand cmd =...

How to set read permission on the private key file of X.509 certificate from .NET

Here is the code to add a pfx to the Cert store. X509Store store = new X509Store( StoreName.My, StoreLocation.LocalMachine ); store.Open( OpenFlags.ReadWrite ); X509Certificate2 cert = new X509Certificate2( "test.pfx", "password" ); store.Add( cert ); store.Close(); However, I couldn't find a way to set permission for NetworkService t...

Managed C++ wrappers for legacy C++ libraries

We're looking at writing a .Net-callable wrapper for some legacy C++ libraries using managed C++. It all looks pretty easy. Is there anything we need to watch out for? ...

Multithread a unit test

In order to test concurrency issues, I want to call the same method on two different threads at exactly the same time using a unit test. In fact I probably want to call the same method on several threads at the same time. I'm using Microsoft's built in unit tester for VS2008. My thoughts are that I would lock an object and then synchro...

Is it a best practice to specify an initial capcity for collections?

A lot of the collection classes in .Net (i.e., List<T>, Dictionary<TKey, TValue>) have an overloaded constructor that lets you specify an initial capacity size. Is it a best practice to use this constructor? If so, is there a rule of them as to some kind of "Magic Number" you should use? It's one thing If I know the exact size ahead of t...

Built-In Character Casing functions in .Net

Are there any built-in functions in .Net that allow to capitalize strings, or handling proper casing? I know there are some somewhere in the Microsoft.VB namespace, but I want to avoid those if possible. I'm aware of functions like string.ToUpper and string.ToLower() functions however it affects the entire string. I am looking to someth...

Converting MSSQL GetUTCDate() into PHP/Unix/MySQL Ticks

I'm inserting a DateTime into MsSQL using the GetUTCDate() function provided by MsSQL. I need to convert the time in C# to show it as the Unix / MySQL integer, so that it can be eventually manipulated with PHP. I believe the Unix / PHP / MySQL ticks start at 1/1/1970, but I'm not sure how I would convert the equiv MsSql / C# time into ...

homesite attribute for .NET 2.0 SP1 aka download location for installers

When including .NET 2.0 as a dependency in a setup project, the project is able to automatically download .NET 2.0 from the web if the machine needs it. The attribute that tells the setup project where this download location is does not seem to exist for .NET 2.0 SP1. Does a 'homesite' location exist for .NET 2.0 SP1? It makes the d...

Clickonce & Isolated Storage

Has anyone had issues with the contents of an isolated storage directory go missing or not update properly after a click once automated deployment? ...

Filtering on multiple DataTables in a DataSet

I have a DataSet containing multiple DataTables. I want to display information from the Product DataTable, which is the center table of the DataSet. But I want to be able to filter the DataSet on values from the surrounding tables. For example, I want to get all the Products that have a Feature (DataTable) named Width and have a Supplie...

What is the real advantage of returning ICollection<T> instead of a List<T>?

I've read a couple of blog posts mentioning that for public APIs we should always return ICollection (or IEnumerable) instead of List. What is the real advantage of returning ICollection instead of a List? Thanks! ...