.net

Handling transaction context using method attribute in linq to sql

Is there a way to just put an attribute to a method so that the whole code in the method is executed in a transaction scope? I've seen this done in sharp architecture but I'm using Linq to sql not nhibernate. Thanks! This what I would like to do: [Transaction] public void InsertCustomer(Customer customer) { //insert customer } So th...

Killing a deadlocked Task in .NET 4 TPL

I'd like to start using the Task Parallel Library, as this is the recommended framework going forward for performing asynchronous operations. One thing I haven't been able to find is any means of forcible Abort, such as what Thread.Abort provides. My particular concern is that I schedule tasks running code that I don't wish to complete...

What is the best way to save a list of objects to an XML file and load that list back using C#?

I have a list of "Gesture" classes in my application: List<Gesture> gestures = new List<Gesture>(); These gesture classes are pretty simple: public class Gesture { public String Name { get; set; } public List<Point> Points { get; set; } public List<Point> TransformedPoints { get; set; } public Gesture(List<Point>...

is it possible to put a WCF Router service infront of a RIA Service

We would like to protect the database and not have connections to it in the DMZ, it is possible to to use the new WCF Router services to redirect to RIA? ...

How to use SerialPort in .Net by using DataReceived event?

I know the DataReceived event is fired on a background thread. How do I tell the GUI thread to show the data in the event handler? ...

LinqToSql Select to a class then do more queries

I have a LINQ query running with multiple joins and I want to pass it around as an IQueryable<T> and apply additional filters in other methods. The problem is that I can't work out how to pass around a var data type and keep it strongly typed, and if I try to put it in my own class (EG: .Select((a,b) => new MyClass(a,b))) I get errors w...

Does a custom DataGridView Cell have to have a parameterless constructor?

I want a slight variation of the custom cell example from the MS website How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance by passing an argument to the custom cell constructor so I could use it later, namely to evaluate something when painting the cell. Private _o...

How to mock ISerializable classes with Moq?

Hi there, I'm completly new to Moq and now trying to create a mock for System.Reflection.Assembly class. I'm using this code: var mockAssembly = new Mock<Assembly>(); mockAssembly.Setup( x => x.GetTypes() ).Returns( new Type[] { typeof( Type1 ), typeof( Type2 ) } ); But when I run tests I get next exception: System.A...

how to fetch xml data from ascx page url?

i have the url for ascx page and i want to fetch the xml data from that page using the page url...is it possible in .net ...

Can I get the method local variables through a stack trace in C#?

I want to get a detailed log about my stack trace. I can get a StackFrame and then the method and then get all the parameters of that method. Just as the following code: StackTrace st = new StackTrace(); StackFrame[] sfs = st.GetFrames(); foreach (StackFrame sf in sfs) { Me...

Do you still need to dispose attachments in .net v4 System.Net.Mail?

With .net v3.5 or less it was required to manually dispose attachments after sending an email using SMTP client, is this still required in .net v4? ...

When should I use Yield in c#?

I have a vage understanding of the Yield keyword in c#, but I haven't yet seen the need to use it in my code. This probably comes from a lack of understanding of it.. So; What are some typical good usages of Yield? ...

Server.Transfer - What could be the issue here?

We have implemented a website with the ability for the user to post his actioncode. This then will be checked by the code and when the user has a price the website will Server.Transfer him to another page. The strange thing here is that the user information will be submitted to the database and the actioncode can't be used again. Here we...

Anything new for WinForms in .NET 4.0

I could not find any information about new WinForm features, exept for this blog post: http://blog.codinglight.com/2009/05/future-of-winforms-whats-changed-in.html which states: 213 types were changed, and 9 types were added. 596 methods were changed, 50 were added, and 8 were removed. So whats in these changes, for joe deve...

Asp.Net 2 integrated sites How to Logout second site programatically.

Hi , I am working with an asp.net 2.0 site (call it site 1) which has an iframe in it which loads up another site (site2) which is also an asp.net site which is developed by our team. When you log onto site 1 then behind the scenes site 2 is also logged in so that when you click the iframe tab then this displays site 2 with the user log...

Using Generics to typecast object type to generic type

I am very new to generics and trying to implement it. How can i use it here. private T returnValueFromGrid(int RowNo, int ColNo) { return (T) dgvCurrencyMaster.Rows[RowNo].Cells[ColNo].Value; } I am trying to convert below value to generic type and then return it. dgvCurrencyMaster.Rows[RowNo].Ce...

C# delegate or Func for 'all methods'?

Hi, i've read something about Func's and delegates and that they can help you to pass a method as a parameter. Now i have a cachingservice, and it has this declaration: public static void AddToCache<T>(T model, double millisecs, string cacheId) where T : class public static T GetFromCache<T>(string cacheId) where T : class So in a pl...

Start a process as LocalSystem using ProcessStartInfo

I am trying to start a process as the LocalSystem account using this code ProcessStartInfo _startInfo = new ProcessStartInfo(commandName); _startInfo.UseShellExecute = false; _startInfo.UserName = @"NT AUTHORITY\SYSTEM"; _startInfo.CreateNoWindow = true; _startInfo.Arguments = argument; _startInfo.RedirectStandardOutput = true; us...

Single windows service to provide access to cached data?

I need a solution where I have a single windows service providing access to cached data to various consumers: To an MVC web application, a .Net Assembly (COM interop) used within an classic ASP page, other windows services, a windows forms application. So the data must be accessible from various processes. The data being cached is read-o...

TextInfo.ToTitleCase does not work as expected for ALL CAPS strings

I was trying to use TextInfo.ToTitleCase to convert some names to proper case. it works fine for strings in lowercase and mixed case but for strings with all characters in Upper case, it returns the input string as is. Nothing about this behavior is mentioned in MSDN documentation, any insights? ...