chetan Allipur

chetan Allipur

  • NA
  • 541
  • 166.9k

How to use the Dispatcher in windows form Application.

Jun 9 2017 3:21 AM
How to use the Dispatcher in windows form Application.
 
I am getting error on Dispatcher Keyword.
 
here is my code.
 
private void btnOk_Click(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(new Action(OpenDocument));
OpenNewFile opn = new OpenNewFile();
opn.Hide();
}
public void OpenDocument()
{
if (cbRegion.SelectedIndex >= 0 && cbPaperSize.SelectedIndex >= 0 && cbFont.SelectedIndex >= 0 && cbTemplateSection.SelectedIndex >= 0 && cbTemplateDocument.SelectedIndex >= 0)
{
try
{
object missing = System.Reflection.Missing.Value;
if (!File.Exists(destinationPath))
{
File.Copy(sourcepath, destinationPath, true);
}
//Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application();
//Microsoft.Office.Interop.Word.Document oWordDoc = Globals.ThisAddIn.Application.ActiveDocument;
Microsoft.Office.Interop.Word.Application ap = Globals.ThisAddIn.Application;
Microsoft.Office.Interop.Word.Document oWordDoc = ap.ActiveDocument;
oWordDoc = ap.Documents.Open(destinationPath, missing, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing
, missing, missing, missing);
oWordDoc = ap.ActiveDocument;
ap.Visible = true;
ap.Activate();
}
catch (Exception ex)
{
throw ex;
}
}
else
{
MessageBox.Show("Please select the value form combobox", "BOX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

Answers (6)