Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using ClosedXML.Excel;
- namespace TestSavingTwoBigFiles
- {
- public class Program
- {
- private static string folderPath = @"C:FOLDERPATH";
- private static string fileName1 = folderPath + "FILENAME1.xlsm";
- private static string fileName2 = folderPath + "FILENAME2.xlsm";
- public static void StartThread1()
- {
- Console.WriteLine("Creating first file...");
- var wb = new XLWorkbook(fileName1, XLEventTracking.Disabled);
- try
- {
- using (wb)
- {
- using (var ms = new MemoryStream())
- {
- Console.WriteLine("Saving first file...");
- wb.SaveAs(ms);
- }
- }
- Console.WriteLine("First file saved successfully");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- Console.ReadLine();
- }
- }
- public static void StartThread2()
- {
- Console.WriteLine("Creating second file...");
- var wb = new XLWorkbook(fileName2, XLEventTracking.Disabled);
- try
- {
- using (wb)
- {
- using (var ms = new MemoryStream())
- {
- Console.WriteLine("Saving second file...");
- wb.SaveAs(ms);
- }
- }
- Console.WriteLine("Second file saved successfully");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- Console.ReadLine();
- }
- }
- public static void Main(string[] args)
- {
- var thread1Start = new ThreadStart(StartThread1);
- var thread1 = new Thread(thread1Start);
- Console.WriteLine("Starting first thread");
- thread1.Start();
- var thread2Start = new ThreadStart(StartThread2);
- var thread2 = new Thread(thread2Start);
- Console.WriteLine("Starting second thread");
- thread2.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement