vb.net - .NET COM assembly interacting with Excel via BackgroundWorker -


i writing (and teaching myself how write) experimental assembly in vb.net 3.5 exposed via com , called excel vba code initiate instance of class traps excel events , perform functions on active workbook in excel.

to initiate class, reference excel application passed vba (i using pia excel in assembly).

i needed perform time-consuming operation on active workbook assembly decided use backgroundworker in winform can display progress dialog operation whilst operation completes in background.

i know if there problems interacting excel via com using background worker in way? reason asking main class in assembly holds reference excel application object, , passed backgroundworker can determine active workbook , perform operations on it. accessing workbook (not other objects) through 1 procedure.

for reason have in head excel might not - right?

if refering this:

  • getting method call vba vb.net code
  • spin off new thread (or worker thread) , handing on reference workbook (or excel.application, range; doesn't matter) (via parameters, statics... doesn't matter)
  • use original thread show ui while background thread accesses excel

then, no; cannot that.

excel vba sta environment. access excel object model, in , out, must happen same thread. don't pick thread either; has thread called method begin with.

to run code accessing excel worker thread, have "marshal" interface pointer worker thread. mashalling creates pair of com wrappers (called 'proxy/stub' pairs) shuttle method call accross threads needed - similar happens when use form.invoke() method in .net. don't know off top of head how in .net. not first approach anyway.

another alternative not access excel object worker thread, use helpers in main form object (you want form, don't you?). let worker thread call helpers via form.invoke() make sure run ui thread (the thread vba used call you). functionally same first alternative, except .net work, instead of com.

a third approach, not use worker threads @ - vb way: create ui 1 , thread; show it, , work load event of form. call application.doevents() once in while (a few times second) let ui operate reseamblance of smoothness.

a fourth alternative turn problem around. use brand new thread instead of pool thread (which backgroundworker) , handle ui there. reverse roles here: main thread fancy work, while thread creates form , shows ui. again, make sure use form.invoke() update progress window. make sure dispose() thread when you're done. might preferred approach.

or use hourglass mouse pointer... how "slow" "slow"?


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -