Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using ClosedXML.Excel;
  9.  
  10. namespace TestSavingTwoBigFiles
  11. {
  12. public class Program
  13. {
  14. private static string folderPath = @"C:FOLDERPATH";
  15. private static string fileName1 = folderPath + "FILENAME1.xlsm";
  16. private static string fileName2 = folderPath + "FILENAME2.xlsm";
  17.  
  18. public static void StartThread1()
  19. {
  20. Console.WriteLine("Creating first file...");
  21. var wb = new XLWorkbook(fileName1, XLEventTracking.Disabled);
  22. try
  23. {
  24. using (wb)
  25. {
  26. using (var ms = new MemoryStream())
  27. {
  28. Console.WriteLine("Saving first file...");
  29. wb.SaveAs(ms);
  30. }
  31. }
  32. Console.WriteLine("First file saved successfully");
  33. }
  34. catch (Exception ex)
  35. {
  36. Console.WriteLine(ex);
  37. Console.ReadLine();
  38. }
  39. }
  40.  
  41. public static void StartThread2()
  42. {
  43. Console.WriteLine("Creating second file...");
  44. var wb = new XLWorkbook(fileName2, XLEventTracking.Disabled);
  45. try
  46. {
  47. using (wb)
  48. {
  49. using (var ms = new MemoryStream())
  50. {
  51. Console.WriteLine("Saving second file...");
  52. wb.SaveAs(ms);
  53. }
  54. }
  55. Console.WriteLine("Second file saved successfully");
  56. }
  57. catch (Exception ex)
  58. {
  59. Console.WriteLine(ex);
  60. Console.ReadLine();
  61. }
  62. }
  63.  
  64. public static void Main(string[] args)
  65. {
  66. var thread1Start = new ThreadStart(StartThread1);
  67. var thread1 = new Thread(thread1Start);
  68. Console.WriteLine("Starting first thread");
  69. thread1.Start();
  70.  
  71. var thread2Start = new ThreadStart(StartThread2);
  72. var thread2 = new Thread(thread2Start);
  73. Console.WriteLine("Starting second thread");
  74. thread2.Start();
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement