multithreading - C# WIA Transfer method locks UI thread -


i have problem causing me headaches. have winform application shows simple dialog users button: "scan". button's click handler, how imagine, starts scan operation using wia com object. in terms of code, when button has pressed creates new async task calls transfer method of item class. problem ui thread freezes until scan ends, although scan object working on thread. documentation on msdn says:

"transfer version of showtransfer not display ui or allow user cancel transfer."

so assumed that, sentence "not display ui", means dialog gets created anyway remains invisible. dialog then, hooks main thread (ui) , causes freeze (in same way modal dialog does). in fact when i've tried use showtransfer method has opened dialog ui thread of application didn't suffer freeze.

this code:

var progress = new progress<string>(s => labelcontrol1.text = s);  var scheduler = taskscheduler.fromcurrentsynchronizationcontext(); var cancelsrc = new cancellationtokensource();  await task.factory.startnew(() => {          var facade = new scanfacade();           facade.scan(progress);           }, cancelsrc.token, taskcreationoptions.longrunning, scheduler); 

and part of scan method calls transfer:

var imagefile = (imagefile) _item.transfer(formatid.wiaformattiff); var buffer = (byte[])imagefile.filedata.get_binarydata();  return image.fromstream(new memorystream(buffer)) bitmap; 

are assumptions correct? how can avoid behavior without using wia dialog?

note: threads both in sta

thank in advance

when create new task pass in taskscheduler created using taskscheduler.fromcurrentsynchronizationcontext();, means code run in ui thread, not thread. need not marshal code ui thread if don't want run in ui thread.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -