.net

What happens to Monitor.Enter without a matching Monitor.Exit?

If you have some blocks of code that you would like to prevent execution of when the object is being exited and cleaned up, could a lock be used to prevent the execution? Monitor.TryEnter(cleanupLock, ref acquiredLock); TryEnter could be used to ensure that the code is not executed, and since it does not wait for the lock there will n...

how to substring from a string using c#?

string format is always like this "FirstName=ABC;LastName=XZY;Username=User1;Password=1234". I need the only UserName value (which is 'User1' in this case). I wanna achieve this in minimum line of code using substring method (or something else). Help? ...

Dynamically Adding items to an un-order list in asp.net

if i create a html ul. and wanted to dynamically add list items to this list. so i have : <ul id="test" runat="server"> </ul> is there a way i can add list item to this list dynamically in asp.net i am using vb ...

Monitor files accessed by windows

Is there a way to hook into the windows API to view all files accessed by the operating system? ...

How to access app configuration from a .dll ?

I recently broke out a part of my winform app in a .dll. Some of the classes in that dll wants fetch/store user settings. The classes just used the VS generated Settings file so it just did Properties.Settings.Default.SomeSetting = var;Properties.Settings.Default.Save() etc. What are my options now that I moved that code out to a clas...

should I include the @ when using SqlCommand.Parameters.AddWithValue?

I have always included the at sign in the parameter name when using AddWithValue, but I just noticed some code written by someone else that doesn't use it. Is one way more correct than the other? cmd.Parameters.AddWithValue("ixCustomer", ixCustomer); or cmd.Parameters.AddWithValue("@ixCustomer", ixCustomer); ...

Process.Start with different credentials with UAC on.

I am trying to start another process with Process.Start running under different credentials with the UAC turned on. I get the following error: System.ComponentModel.Win32Exception: Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has...

How to get the height of Label control in Winforms

My label is wrapping the text due to the length of the text. The height property returns the correct value only if there is a single line. How can I get the correct height? Thanks. Solution: I was creating the label dynamically and checking the height then. Later the panel on which the label was residing was added to a form, changing t...

Timers in a .NET application

I would like to know what kind of timers can be used in a C# application and what are their implications in term of cuncurrency in a multi-threaded environment. Could you explain me or link me to an esaustive tutorial? Thank you. ...

Requirements for using an SQL database in a program.

I have been experimenting with writing applications that use a local SQL Database to store data. I am using Visual Studio to create Windows Forms applications and then connecting them to a database and using LINQ to SQL to pass data to and from the DB. My question is, when I deploy this program on a target machine, what requirements must...

Reusing a filestream

In the past I've always used a FileStream object to write or rewrite an entire file after which I would immediately close the stream. However, now I'm working on a program in which I want to keep a FileStream open in order to allow the user to retain access to the file while they are working in between saves. ( See my previous question)....

Performance comparison for logging to MSMQ / text file / database

We have several choices for logging in our .NET (C#) server application. We are going to use Enterprise Library. So here are the ways to go: 1) Writing log to MSMQ synchronously, then reading MSMQ with Win Service. Queue is on the local machine for server application. 2) Writing log to disk (i.e. rolling text files) synchronously. 3) W...

MVC 2.0:How to send simple TextBox value to Action with an ActionLink?

Basically, i don't want to use <input type="submit"> mainly because it's a button, i'd rather user ActionLink, so i am using Ajax.ActionLink, and i'm not sure what to place in the routeValues argument for it to pickup the new (edited) data (user enters comments etc) and send it to my action. would any of you know? thanks. this is what i...

How to immediately exit a Windows Form .Net application?

In our app, we have a quite extensive exception handling mechanism. At some point in our error handling logic, we want to terminate the application -- right at this point with no further code execution. Our current code use Environment.Exit() to do that. After a call to Environment.Exit(), some code is still executed. For instance, the G...

Replacement for ServerXMLHTTP30

Hello all, What is the best replacement for ServerXMLHTTP30 in .NET 3.5. Is HttpWebRequest good candidate? I am in the process of creating an application that will get a XML stream as a response to a request. Appreciate any tips/help or guidence. thank you. --Ranjit ...

How to clear Viewstate?

I am having a problem in which two controls which are added programmatically are trying to load each other viewstate, I want to clear the viewstate before loading the controls, I tried Viewstate.Clear but it did nothing, when I disable viewstate on the container of my controls everything works fine except that the control's state is not ...

KeyTime property on KeyFrame object must be set to a non-negative TimeSpan value?

All, Can someone tell me why this KeyTime is telling me it is a negative value at runtime? I've removed some logic that builds a path to an image. public Storyboard CreateAnimationStoryBoard(DependencyObject dependencyObjectTarget,Image targetImage) { try { Storyboard sb = new Storyboard(); S...

How do I encode diacritics for Twitter updates?

I have my own Twitter API and I've received a couple emails about a problem when trying to post a status update with accent marks and other diacritics. I would like to encode these so that the status update still has them. I know there are ways to remove the diacritic, but I would like to keep it. I read the Twitter Counting Character...

Take next parameter as field width in String.Format

In C#, I have a width I want to use for some strings, but I won't know that width until runtime. I'm doing something like this: string.Format("{0, " + digits + "}", value) // prints 123 as " 123" Is there a string formatting directive that lets me specify this without smashing my own format string together like this? I looked arou...

Encrypt ApplicationServices ConnectionString

Is there a way where I can set the .NET ApplicationServices connection string in the code behind? Instead of having plain text in my web.config? Or can I just put the encrypted value there and then decrypt and pass it again? Thanks! ...