What are alternative ways to suspend and resume a thread?

You’ll want to use an AutoResetEvent EventWaitHandle. Say you want to do something like this (NOTE: don’t do this!): private Thread myThread; private void WorkerThread() { myThread = Thread.CurrentThread; while (true) { myThread.Suspend(); //Do work. } } public void StartWorking() { myThread.Resume(); } Like others have said, this is a bad idea. Even though only … Read more

Load vs. Shown events in Windows Forms

Avoid using MessageBox.Show() to debug this. It pumps a message loop, disturbing the normal flow of events. The Load event is triggered by Windows sending the WM_SHOWWINDOW message, just before the window becomes visible. There is no Windows notification for “your window is now fully shown”, so the WF designers came up with a trick … Read more

Best method to obfuscate or secure .Net assemblies [closed]

This is a pretty good list of obfuscators from Visual Studio Marketplace Obfuscators ArmDot Crypto Obfuscator Demeanor for .NET DeployLX CodeVeil Dotfuscator .NET Obfuscator Semantic Designs: C# Source Code Obfuscator Smartassembly Spices.Net Xenocode Postbuild 2006 .NET Reactor I have not observed any performance issues when obfuscating my code. If your just sending text basted stack … Read more

What is the best way to store pairs of strings, make an object or use a class in .NET?

The “pair” generic class for .NET is Tuple. You would use it like: var strings=new List<Tuple<string, string>>(); strings.Add(Tuple.Create(“REFERENCE”, “Ref”)); A dictionary is a perfectly acceptable substitute if the left-most string is unique (ie a key). You’ll get errors otherwise. As to whether it’s better to use the built-in collections or create an actual object, depends … Read more

System.ValueType Understanding

ValueType is a little white lie. The built-in numeric types (int, long, byte), char, enums and structs are all value types. This means that they have a different concepts of identity and equivalence to object types. If I do x = y and x and y are reference types, then x and y now point … Read more

Strange Error – CS0012: The type x is defined in an assembly that is not referenced

I’m Mike’s coworker, and we worked out a solution. The type X is defined in his assembly, that is only in the GAC. Even though his ASP.NET web appplication did have a reference, it was failing to load from the GAC only for this UserControl. The rest of the application worked as expected. We confirmed … Read more