troubleshooting Question

Multithreading with Classes in MFC

Avatar of mr_stevie
mr_stevieFlag for Australia asked on
System ProgrammingC++Visual C++.NET
3 Comments2 Solutions687 ViewsLast Modified:
Hello,

I am having trouble implementing multi-threading into my program.
At the moment, I am reading the MSDN libraries but it does not make much sense to me.

To start off, I have two different classes that will output to two different files.

For example, a simple example class is given below.

At the moment, I have them outputting one after the other. Although performance isn't really an issue at the moment, I will be eventually be dealing large amounts of data and would like the classes to be doing calculations and output independently on different threads.

I intended to use a Worker Thread but I am unsure how what parameters to pass through to the AfxBeginThread() function.

If anyone could provide any assistance, will be greatly appreciated!

Thank you in advance!
void CLASSA::output()
{
	ofstream output( output1.txt );

	for( unsigned int x = 0; x < 100; x++ )
	{
		output << x << "\n";
	}

	output.close();
}

void CLASSB::output()
{
	ofstream output( output2.txt );

	for( unsigned int x = 0; x < 100; x++ )
	{
		output << x << "\n";
	}

	output.close();
}

Open in new window

ASKER CERTIFIED SOLUTION
AndyAinscow
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros