c# - Calling Interop Word Reference in BackGroundWorker and RichTextBox Writing -
i have simple application that:
1-) openfiledialog button select word document open. 2-) readbutton open word document path defined.i read func open word document
private void readmsword() { string filepath = dosyayol.text; seek { microsoft.office.interop.word.application word = new microsoft.office.interop.word.application(); object miss = system.reflection.missing.value; object path = dosyayol.text; object readonly = false; microsoft.office.interop.word.document docs = word.documents.open(ref path, ref miss, ref readonly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss); docs.activewindow.selection.wholestory(); docs.activewindow.selection.copy(); idataobject info = clipboard.getdataobject(); wordtext.text = data.getdata(dataformats.text).tostring(); image img = (image)data.getdata(dataformats.bitmap); ((microsoft.office.interop.word._document)docs).close(ref miss, ref miss, ref miss); } grab (exception ex) { messagebox.show(ex.message); } }
in fuction example: programme gives error on line
wordtext.text = data.getdata(dataformats.text).tostring();
"object reference not set instance of object"
read button click event
private void readbutton_click(object sender, eventargs e) { if (string.isnullorempty(dosyayol.text) || string.isnullorwhitespace(dosyayol.text)) { messagebox.show("bir dosya seçmeden okuma işlemi yapamazsınız!", "dijital arşiv güncelleme", messageboxbuttons.ok, messageboxicon.stop); return; } else { backgroundworker1.runworkerasync(); } }
backgroundworker dowork
private void backgroundworker1_dowork(object sender, doworkeventargs e) { readmsword(); }
and progresschanged event of bgw
private void backgroundworker1_progresschanged(object sender, progresschangedeventargs e) { progressbar1.value = e.progresspercentage; }
how can achive study progress bar thread percentage? , show progress bar.
c# multithreading progress-bar backgroundworker
No comments:
Post a Comment