Windows Workflow Foundation 4.0 Tutorials / Introductions [closed]

I’ve discovered recently myself that there’s not a lot of online content available. Check out the Workflow Foundation 4 Resources and Community site on MSDN for some good articles and labs. Also, download the WF4 Samples. I’ve learned a lot from poking through these samples and trying things out locally. As for the WHY of … Read more

Sequential processing of asynchronous tasks

Here’s how it would work with async: try { await FooAsync(); await BarAsync(); await FubarAsync(); Console.WriteLine(“All done”); } catch(Exception e) // For illustration purposes only. Catch specific exceptions! { Console.WriteLine(e); } This would work on .NET 4.0 if you installed the (prerelease) Microsoft.Bcl.Async package. Since you’re stuck on VS2010, you can use a variant of … Read more

Lazy initialization in .NET 4

The purpose of the Lazy feature in .NET 4.0 is to replace a pattern many developers used previously with properties. The “old” way would be something like private MyClass _myProperty; public MyClass MyProperty { get { if (_myProperty == null) { _myProperty = new MyClass(); } return _myProperty; } } This way, _myProperty only gets … Read more

Non-readonly fields referenced in GetHashCode()

To summarise what was discussed in the comments: Hashing is designed to provide a value that doesn’t change for a given object, no matter what happens to it – hence it’s best to depend only on readonly fields in your GetHashCode method. Firstly, I would suggest making the name and lname field readonly, because they … Read more

.NET 4.0 build server reference assemblies warnings MSB3644 [duplicate]

Ok I found a solution that works. You need to do two things: First add FrameworkPathOverride as a commandline parameter and point it to the references assemblies directory. Something like msbuild -p:FrameworkPathOverride=”C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0″ The second thing you need to do is find a full version of the reference assemblies directory. Since the copy installed … Read more

Unblock File from within .net 4 c#

Based on your input I have done the following code: public class FileUnblocker { [DllImport(“kernel32”, CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool DeleteFile(string name); public bool Unblock(string fileName) { return DeleteFile(fileName + “:Zone.Identifier”); } } Thanks to Stuart Dunkeld, Alex K(+1) and Sven to show me the direction. UPDATE I … Read more

Is there a built-in C# method to go from an empty string to null value?

You can use an extension method: public static class Extensions { public static string NullIfWhiteSpace(this string value) { if (String.IsNullOrWhiteSpace(value)) { return null; } return value; } } Which you could use like that: var mySqlValue = tbCustomerId.Text.NullIfWhiteSpace(); I don’t really know what you imagine by something better than Extension methods. How do you define … Read more

Specifying a Thread’s Name when using Task.StartNew

Well, this works: class Program { static void Main(string[] args) { var task = Task.Factory.StartNew(() => { Thread.CurrentThread.Name = “foo”; Thread.Sleep(10000); // Use Debug + Break to see it }); task.Wait(); } } There’s a problem however, the threadpool thread gets recycled and won’t change its name. This can be confusing, you’ll see it running … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)