0

I have a vb.net windows form which generates report that is displayed using crystal report (backend is sql server database tables). Once the report is generated and shown a procedure updates the contents of the report on to a table. This update process takes around a minute. This update process freezes the report window and the cursor gets stuck till the update process is complete.

So I moved the code from the update procedure to a class and invoked it as a thread. The report is accessible immediately on display and the update process runs in background.

        Dim urctThread As Thread

        Dim csURCT As ClassURCT = New ClassUpdateRCT()

        urctThread = New Thread(New ThreadStart(AddressOf csURCT.URCT))
        urctThread.Priority = Threading.ThreadPriority.Lowest
        urctThread.IsBackground = True
        urctThread.Start()

My question here is, what happens if the user closes the form that invoked the thread. Will the thread terminate or will it continue till execution of the update process is complete.

I am new to threading and a layman in programming (self taught). Would appreciate your valued input here.

Regards.

  • A raw thread will continue. Use a [`BackgroundWorker`](https://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker%28v=vs.110%29.aspx) and see [this question](http://stackoverflow.com/q/1731384/11683) for how to cancel it on form close. – GSerg Dec 19 '15 at 07:06
  • GSreg, I have modified my question to include the code creating the thread. I do not want the thread to be terminated however the user may close the form if he wishes to. So will the thread still execute? Or will a BackgroundWorker solve this issue. Thanks for the prompt reply. – user3321952 Dec 19 '15 at 07:37
  • If you want the thread to continue then you must set its IsBackground property to False. – Hans Passant Dec 19 '15 at 09:03

0 Answers0