Recently I was a bit busy with multiple projects involving PHP and C#.NET. I feel so guilty that I did not manage the time very well to update my simple site as my work portfolio.
I was asked to create a simple application to help company employees to manage virtual image VDI files used virtual box. I decided to go for it using C# .net in visual studio express 2010.
It is actually my first application in c# using visual studio. I had plenty of problems and issues as I stepped through this little development. One of bigger issues I faced was that I had to use a backgroundWorker as a separate thread to handle progress bar report updating. When clicking on the cancel file transfer button, the backgroundWorker should stop working and ftp transfer process should also be stopped. However, the problem was that backgroundWorker is still running and ignoring my termination code even if I use “backgroundWorker1.CancelAsync()”.
There are several answers as I searched through Google. Most of them did not provide clear solutions until I found out that “backgroundWorker1.CancellationPending” must be set to true, and doWork event must be set to “Cancelled” by using “e.Cancel = true;“. And in “backgroundWorker1_RunWorkerCompleted” method, try to get event cancelled status to notify user that backgroundWorker has already been terminated.
The credit is given from this site “http://www.dotneat.net/2009/02/10/BackgroundworkerExample.aspx“. The solution is clear and well explained.
In this little application, I learned quite a bit about c# programming using visual studio. Looking forward to make more applications and learn more stuff.
I will list more interesting learning about creating this application later.