CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Question 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
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: BackgroundWorker Component

    Quote Originally Posted by ideru View Post
    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 .
    And how exactly is it "crashing"?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    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
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: BackgroundWorker Component

    Quote Originally Posted by ideru View Post
    it seems that the culprit was the global file pointer I was using. It was null, so of course it crashed
    But why don't you check whether it is NULL or not before using this pointer?
    Victor Nijegorodov

  5. #5
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Re: BackgroundWorker Component

    Quote Originally Posted by VictorN View Post
    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
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured