Making Class Variables and Objects Thread Safe

Simple Locking Approach using namespace System::Threading; Create a flag private: bool ClassObjectsLocked; In your constructor set it up ClassObjectsLocked = false; Then in functions which want to alter values but may be on a different thread while (ClassObjectsLocked) Thread::Sleep(1); In functions which want to read values ClassObjectsLocked = true; … ClassObjectsLocked = false;

Read More

Start a new process in another thread

Good Resources http://www.csharp-examples.net/create-asynchronous-method/ New process must be in a separate class using namespace System::Threading; (you can just create a new named class before the class you are currently in when working in a form etc) public ref class InstallerUpdaterClass { public: static void UpdaterStartSilent(void) { try { //Pause before starting Thread::Sleep(10000); //mS String ^UpdaterFilename; UpdaterFilename […]

Read More

Sleep

using namespace System::Threading; Pause This allows you to literally pause execution where you are in the current function – it just pauses this thread Thread::Sleep(1000); //mS System::Threading::Thread::Sleep(1000); //mS Threading.Thread.Sleep(New TimeSpan(0, 1, 0))

Read More

Thread Safe Calls

If your application is doing asynchronous things, for instance a form has a callback function from a class receiving say some communications, then you will need to deal with calls to it in a thread safe way. The reason is that forms run on a single thread, but events in the other class will not […]

Read More