Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Im new to Nlog.
I manged to connecto to MySql and write logs to a table.
Now I want to do it Async.
I added AsyncWrapper to my xml configuration file. nothing was written to the DB.
I added Flush() in my own wrapper program. it took the same amount of time - approx 1 minute for 50 records.
There is no example of how to do it with DB, only with file, Can someone please post an example for Async connection to a DB that works.
10x in advance
Jacob
Posted

1 solution

I'm not sure this is the right way to do it, but you can try this:

using System.ComponentModel;
using MySql.Data.MySqlClient;

public void Flush()
{
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += (sender, e) =>
     {
         // do some work, just an example
         e.Result = MySqlHelper.ExecuteNonQuery("your-connectionstring-here", "your-commandtext-here");
         // do some work
     };
     worker.RunWorkerCompleted += (sender, e) =>
     {
         MessageBox.Show((int)e.Result + " rows affected.", "Success");
     };
     worker.RunWorkerAsync();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900