Wednesday, March 16, 2016

The calling thread cannot access this object because a different thread owns it.


On your do work

  private void worker_DoWork(object sender, DoWorkEventArgs e)  
     {  
       this.Dispatcher.Invoke((Action) (() =>  
       {  
         // Your code  
       }));  
     }  


Wednesday, March 9, 2016

C# - Process.Start a ClickOnce application





  string publisher_name = "ABCPublisher";  
       string product_name = "FaxManFMFFileCreator";  
       var shortcutName = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\\",publisher_name, "\\", product_name, ".appref-ms");  
       Process.Start(shortcutName);  




Devexpress report Export in to file

Test is the devexpress report and you can export in different format.


  XtraReport report = new Test();  
  report.CreateDocument();  
 report.ExportToText("D:\\test1.doc");  


C# kill specific process


  //Threading for speacific printer otherwise it will open default Faxman printer  
       Task.Factory.StartNew(() =>  
       {  
         Thread.Sleep(5000);  
         // Killing Process of default printer  
         Process[] processes = Process.GetProcessesByName("FaxManFMFFileCreator");  
         foreach (var process in processes)  
         {  
           process.Kill();  
         }  
       });  


Tuesday, March 8, 2016

The calling thread must be STA, because many UI components require this.


  // Create a thread  
       Thread newWindowThread = new Thread(new ThreadStart(() =>  
       {  
         // You can use your code  
         // Create and show the Window  
         FaxImageLoad obj = new FaxImageLoad(destination);  
         obj.Show();  
         // Start the Dispatcher Processing  
         System.Windows.Threading.Dispatcher.Run();  
       }));  
       // Set the apartment state  
       newWindowThread.SetApartmentState(ApartmentState.STA);  
       // Make the thread a background thread  
       newWindowThread.IsBackground = true;  
       // Start the thread  
       newWindowThread.Start();  

Monday, March 7, 2016

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.":null

Create app.config and modify it


 <?xml version="1.0" encoding="utf-8" ?>  
 <configuration>  
  <startup useLegacyV2RuntimeActivationPolicy="true">  
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />  
  </startup>  
 </configuration>  



SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...