// Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. // eventLog1.WriteEntry("File: " + e.FullPath + " # " + e.ChangeType); if (e.FullPath == (PathList.InvoiceXMLPath + "\\" + PathList.InvoiceXMLFile)) { NoOfEvent++; if (NoOfEvent == 1) { eventLog1.WriteEntry(" Event No: # " + NoOfEvent + " , Process File : " + e.FullPath); ServiceAction.InsertInvoiceXML(e.FullPath, eventLog1); //eventLog1.WriteEntry(" Event No: 1 is now # " + NoOfEvent); } else { // eventLog1.WriteEntry("Second Entry Exit..."); return; } } else { eventLog1.WriteEntry("Some other file is changed !!!"); } }
private void BTNSave_Click(object sender, EventArgs e) { RecordCount = 0; pBar.Enabled = true; pBar.Visible = true; pBar.Style = ProgressBarStyle.Continuous; pBar.Step = 1; pBar.PerformStep(); pBar.Minimum = Int32.Parse(TXTStart.Text); pBar.Maximum = Int32.Parse(TXTEnd.Text); Task t = null; //if (CBUploadType.Text == "SaleRegister") // t = Task.Run(( ) => RecordCount = ER.ReadDataSaleRegister(TXTFileName.Text, // Int32.Parse(TXTStart.Text.Trim()), // Int32.Parse(TXTEnd.Text.Trim()), pBar, "SaleRegister")); //else if (CBUploadType.Text == "Purchase") // t = Task.Run(( ) => RecordCount = ER.ReadPurchase(TXTFileName.Text, // Int32.Parse(TXTStart.Text.Trim()), // Int32.Parse(TXTEnd.Text.Trim()), pBar, "Puchase")); //else if (CBUploadType.Text == "SaleItemWise") //{ // t = Task.Run(( ) => RecordCount = ER.ReadDataSales(TXTFileName.Text, // Int32.Parse(TXTStart.Text.Trim()), // Int32.Parse(TXTEnd.Text.Trim()), pBar, "Sale")); //} //else if (CBUploadType.Text == "Customer") //{ // t = Task.Run(( ) => RecordCount = ER.ReadCustomer(TXTFileName.Text, // Int32.Parse(TXTStart.Text.Trim()), // Int32.Parse(TXTEnd.Text.Trim()), pBar, "Customer")); //} // else if (CBUploadType.Text == "VoyBill") { //Current Process // t = Task.Run (()=>VoyBillUpload.ReadVoyBillXML(TXTFileName.Text )); //return; t = Task.Run(() => ServiceAction.InsertInvoiceXML(TXTFileName.Text)); //VoygerXMLReader.ReadVoyBillXML(TXTFileName.Text)); } //else if ( CBUploadType.Text == "PurchaseRegister" ) //{ // return; //} else { return; } Task q = Task.Run(() => { t.Wait(); if (t.IsCompleted) { MessageBox.Show("Record save, " + RecordCount); // pBar.BeginInvoke(new Action(() => { pBar.Minimum = 0; pBar.Maximum = 0; pBar.Value = 0; pBar.Refresh(); })); } else { Console.WriteLine("Sleeping for 5 sec"); Task.Delay(5000); } }); }