-
May 17th, 2015, 10:16 PM
#1
BackgroundWorker Component
I found this article
https://msdn.microsoft.com/en-us/lib...undworker.aspx
and tried it in my current application.
My backgroundworker will do file saving operation, unfortunately it's crashing now .
Here is the flow of my code:
- Application Starts
- Start Thread to get data from a buffer. The thread is created by
Code:
Thread^ thReceive = gcnew Thread(gcnew ThreadStart(&Form1::ThreadReceiveProc));
Code:
ThreadReceiveProc(){
buffer_data <- save data ( global variable)
}
- When the data size save in buffer data is satisfied , start background worker thread
Code:
backgroundWorker1->RunWorkerAsync(buffer_data_size);
- in DoWork of background worker thead save data to file. The global variable ( buffer_data ) is accessed and save to file.
Code:
fwrite(gbuffer_data sizeof(gbuffer_data, buffer_data_size global_file_pointer);
The worker thread is run whenever the size of the buffer data is reached.
I'm currently debugging but any thoughts on the fwrite don't work?
The code is a bit big, if needed I can try to make a small one.
Thanks for any advice
-
May 18th, 2015, 03:42 AM
#2
Re: BackgroundWorker Component
Originally Posted by ideru
And how exactly is it "crashing"?
Victor Nijegorodov
-
May 18th, 2015, 09:00 PM
#3
Re: BackgroundWorker Component
It me took awhile to figure it out isolating each variable but it seems that the culprit was the global file pointer I was using. It was null, so of course it crashed
-
May 19th, 2015, 12:47 AM
#4
-
May 19th, 2015, 09:53 PM
#5
Re: BackgroundWorker Component
Originally Posted by VictorN
But why don't you check whether it is NULL or not before using this pointer?
I had 2 File Pointers, and the one that was supposed to be use was created and checked if NULL. File is create and opened successfully, but during the write operation I used the other variable, really STUPID .. Live and learn
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|