Form UI Freeezes even after using Backgroundworker when using Flickr.Net API

Topics: Developer Forum, Project Management Forum, User Forum
Jun 30, 2012 at 8:32 AM
Edited Jun 30, 2012 at 8:37 AM

Im working in winforms.I want upload some images using the Flickr.net API.The Images are uploaded but the User Interface freezes.I have inserted the code for uploading in a Background worker

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 
{

 foreach (var item in imagelist)
 { 
flickr.UploadPicture(item, Path.GetFileName(item), null, null, true, false, true); 
 }
 
MessageBox.Show("Success"); 
}


The flickr object is created earlier from another form and passed to this form.I call the worker by

if(worker.IsBusy==false){backgroundWorker1.RunWorkerAsync();} 

when a button is clicked.What is the Problem?

Coordinator
Jun 30, 2012 at 3:23 PM

I've written a test here and it works fine. I have a progress bar updating on the UI thread and the file uploading in a background worker and the progress bar never stops moving. I can also click into the text boxes etc.

As an aside, you probably shouldn't have a MessageBox in your DoWork event, but in the RunCompleted event.

Sam

Jul 1, 2012 at 4:23 AM

Hi,

i had to use STA Thread to solve it.Can you post the Test project so that i can learn how to properly do it.

Thanks

Coordinator
Jul 1, 2012 at 9:04 AM

A sample upload form has been added to the http://flickrnetsamples.codeplex.com/ sample winforms project.

View the source code here: http://flickrnetsamples.codeplex.com/SourceControl/changeset/view/7c4a86d62942#WinForms%2fUploadForm.cs

Sam