Reputation: 37
I was reading a tutorial about multi-threading. However, the tutorial is written in C#. My application, unfortunately, is written in C++\CLI. I would like to know the equivalent code in C++\CLI of the following C# code:
private void button1_Click(object sender, EventArgs e)
{
Thread backgroundThread = new Thread(
new ThreadStart(() =>
{
Thread.Sleep(5000);
MessageBox.Show("Thread completed!");
}
));
backgroundThread.Start();
}
This C# code uses LINQ, which confuses me (I'm new to programming).
Update: I want to make a progress bar that can show the progress of the calculation of a huge loop, which calculates combinations. The application is frozen when calculating the loop, and that's why I need multi-threading.
Thanks in advance.
Upvotes: 0
Views: 3821
Reputation: 504
The equivalent C++/CLI code is the following:
void WorkCompleted()
{
Thread::Sleep(5000);
MessageBox::Show("Thread completed!");
}
void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Thread^ backgroundThread = gcnew Thread(gcnew ThreadStart(this, &Form1::WorkCompleted));
backgroundThread->Start();
}
Upvotes: 2