I started coding my first WPF app and I'm having trouble with a textbox that displays some system info (cpu, memory, disk usage, mac address, etc.).
My apps has navigation between two pages and the said textbox is on one of the pages. The textbox's content is retrieved via WMI queries.
The issue I have noticed is that while navigating to tha page with the textbox it freezes the UI for about two seconds before going to and display the page.
I'm a newbie and my best guess is that eighter the WMI queries(could be badly coded too) are doing that or I'm loading the content in the textbox wrongfully.
An example of how my queries are constructed
public string getCPU()
{
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
StringBuilder sb = new StringBuilder();
foreach (ManagementObject wmi in searcher.Get())
{
try
{
sb.Append("Processor: " + wmi.GetPropertyValue("Name").ToString() + Environment.NewLine);
}
catch
{
return sb.ToString();
}
}
return sb.ToString();
}
public string getRAMsize()
{
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject item in moc)
{
return Convert.ToString(Math.Round(Convert.ToDouble(item.Properties["TotalPhysicalMemory"].Value) / (1024 * 1024 * 1024), 0)) + " GB";
}
return "RAMsize";
}
And this is what I use to retrieve the data in the textbox:
private void TextBox1_Loaded(object sender, RoutedEventArgs e)
{
TextBox1.Text = getCPU();
TextBox1.Text += "Memory: " + getRAMsize() + Environment.NewLine;
TextBox1.Text += "Free Space: " + GetTotalFreeSpace(sysdrive) + " GB" + Environment.NewLine;
if (Is64BitSystem)
{
TextBox1.Text += getOS() + " 64bit" + Environment.NewLine;
}
else
{
TextBox1.Text += getOS() + " 32 Bit" + Environment.NewLine;
}
TextBox1.Text += "MAC Address : " + System.Text.RegularExpressions.Regex.Replace(GetMacAddress().ToString(), ".{2}", "$0 ") + Environment.NewLine;
TextBox1.Text += av();
}
My question is what am I doing wrong and how can I get around with it. In my mind , if the queries are constructed correctly, it would be because they are done again and again everytime the textbox is loaded (on navigation or at startup) and maybe If I could get it to load only once and remember those values(since most of the data should stay the same).
But as I said I'm a noob and any help will be greatly appreciated.
Thanks in advance
You are aquiring your data in the UI Thread.
You should load the data in the background thread and then, since you use wpf, binding the textbox text to a variable.
Example (This code is Copy'n'Paste ready):
// INotifyPropertyChanged is an Interface which enables binding of Properties in your window
public partial class MainWindow : Window, INotifyPropertyChanged
{
private string _systemInformation;
// Stub (works actually)
private bool is64BitSystem = (IntPtr.Size == 8);
// Stub
private string sysdrive = "YOLO\\:";
public MainWindow()
{
InitializeComponent();
// Set Datacontext normally set to a viewmodel but ther is none in this code
this.DataContext = this;
// The Backgroundworker does things in the background (nonblocking)
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += DoItButDontInterruptMeDuh;
bw.RunWorkerAsync();
}
public event PropertyChangedEventHandler PropertyChanged;
public string SystemInformation { get => _systemInformation; set => _systemInformation = value; }
//Stub
public string getCPU()
{
return "Fancy CPU";
}
//Stub
public string getRAMsize()
{
return "1 PB";
}
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
//Stub
private string av()
{
return "Whatever av means.";
}
private void DoItButDontInterruptMeDuh(object sender, DoWorkEventArgs e)
{
// Simulate loading time
Thread.Sleep(5000);
SystemInformation = getCPU();
SystemInformation += "Memory: " + getRAMsize() + Environment.NewLine;
SystemInformation += "Free Space: " + GetTotalFreeSpace(sysdrive) + " GB" + Environment.NewLine;
if (is64BitSystem)
{
SystemInformation += getOS() + " 64bit" + Environment.NewLine;
}
else
{
SystemInformation += getOS() + " 32 Bit" + Environment.NewLine;
}
SystemInformation += "MAC Address : " + System.Text.RegularExpressions.Regex.Replace(GetMacAddress().ToString(), ".{2}", "$0 ") + Environment.NewLine;
SystemInformation += av();
OnPropertyChanged("SystemInformation");
}
//Stub
private object GetMacAddress()
{
return "Macintoshstreet 1234";
}
//Stub
private string getOS()
{
return "Cool OS";
}
//Stub
private string GetTotalFreeSpace(object sysdrive)
{
return "0";
}
}
and in the .xaml:
<TextBox Text={Binding Path=SystemInformation}/>
After checking each and every query I found out that the getCPU one is causing a delay in the load.
I replaced it with a Registry.GetValue, wich is very fast.
Thanks to Sebastian L, because altough his code didn't work for me it put me on the right path and I was able to adapt own code with a backgroundworker to avoid UI freeze of any kind
my working code:
private void TextBox1_Loaded(object sender, RoutedEventArgs e)
{
BackgroundWorker bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.DoWork += new DoWorkEventHandler(delegate (object o, DoWorkEventArgs args)
{
});
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate (object o, RunWorkerCompletedEventArgs args)
{
TextBox1.Text = (string)Registry.GetValue(#"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString", null) + Environment.NewLine;
TextBox1.Text += "Memory: " + getRAMsize() + Environment.NewLine;
TextBox1.Text += "Free Space: " + GetTotalFreeSpace(sysdrive) + " GB" + Environment.NewLine;
if (Is64BitSystem)
{
TextBox1.Text += getOS() + " 64bit" + Environment.NewLine;
}
else
{
TextBox1.Text += getOS() + " 32 Bit" + Environment.NewLine;
}
TextBox1.Text += "MAC Address : " + System.Text.RegularExpressions.Regex.Replace(GetMacAddress().ToString(), ".{2}", "$0 ") + Environment.NewLine;
TextBox1.Text += av();
});
bw.RunWorkerAsync();
}
Related
i want to generate the dynamic Qr code so please help me out how can i build a dynamic Qr code generator that will change during the run time in every 10 seconds
private void btnGenerate_Click(object sender, EventArgs e)
{
QRCoder.QRCodeGenerator QRGenerator = new QRCoder.QRCodeGenerator();
DateTime now = DateTime.Now;
dateTimePickerDate.Text = now.ToLongDateString();
txtTime.Text = now.ToShortTimeString();
var qrText = cmbSubject.Text + "\n" + txtSection.Text + "\n" + dateTimePickerDate.Text + "\n" + txtTime.Text + "\n";
var MyData = QRGenerator.CreateQrCode(cmbSubject.Text + ",\n" + txtSection.Text + ", \n" + dateTimePickerDate.Text + ",\n" + txtTime.Text + ",\n" + txtIP.Text + ",\n", QRCoder.QRCodeGenerator.ECCLevel.H);
var code = new QRCoder.QRCode(MyData);
pcQRImage.Image = code.GetGraphic(50);
}
You need to add a Timerto your Forms project e.g:
private Timer timerInterval = new Timer();
private QRCoder.QRCodeGenerator QRGenerator = new QRCoder.QRCodeGenerator();
private void btnGenerate_Click(object sender, EventArgs e)
{
timerInterval.Enabled = true;
timerInterval.Tick += timerInterval_Tick;
timerInterval.Interval = 10000;
timerInterval.Start();
}
private void timerInterval_Tick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
dateTimePickerDate.Text = now.ToLongDateString();
txtTime.Text = now.ToShortTimeString();
var qrText = cmbSubject.Text + "\n" + txtSection.Text + "\n" + dateTimePickerDate.Text + "\n" + txtTime.Text + "\n";
var MyData = QRGenerator.CreateQrCode(cmbSubject.Text + ",\n" + txtSection.Text + ", \n" + dateTimePickerDate.Text + ",\n" + txtTime.Text + ",\n" + txtIP.Text + ",\n", QRCoder.QRCodeGenerator.ECCLevel.H);
var code = new QRCoder.QRCode(MyData);
pcQRImage.Image = code.GetGraphic(50);
}
It is also possible to use System.Threading.Timer but then it will be necessary to Invoke your Form elements.
Hi you can try this method, this will instantiates the timer to fire every millisecond interval you set.
private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer timerInterval = new System.Timers.Timer();
timerInterval.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timerInterval.Interval = 10000;
timerInterval.Enabled = true;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
QRCoder.QRCodeGenerator QRGenerator = new QRCoder.QRCodeGenerator();
DateTime now = DateTime.Now;
dateTimePickerDate.Text = now.ToLongDateString();
txtTime.Text = now.ToShortTimeString();
var qrText = cmbSubject.Text + "\n" + txtSection.Text + "\n" + dateTimePickerDate.Text + "\n" + txtTime.Text + "\n";
var MyData = QRGenerator.CreateQrCode(cmbSubject.Text + ",\n" + txtSection.Text + ", \n" + dateTimePickerDate.Text + ",\n" + txtTime.Text + ",\n" + txtIP.Text + ",\n", QRCoder.QRCodeGenerator.ECCLevel.H);
var code = new QRCoder.QRCode(MyData);
if(pcQRImage!=null)
{
pcQRImage.Dispose();
pcQRImage.Image = code.GetGraphic(50);
}
else
{
pcQRImage.Image = code.GetGraphic(50);
}
}
I did what #Enigmativity write
here it is:
Action<int, ProgressBar, Label, Label, int, Button> downloadFileAsync = (i, pb, label2, label1, ServID, button1) =>
{
var bd = AppDomain.CurrentDomain.BaseDirectory;
var fn = bd + "/" + i + ".7z";
var down = new WebClient();
DownloadProgressChangedEventHandler dpc = (s, e) =>
{
label1.Text = "Download Update: " + i + " From: " + ServID;
int rec =Convert.ToInt16(e.BytesReceived / 1024);
int total =Convert.ToInt16(e.TotalBytesToReceive / 1024) ;
label2.Text = "Downloaded: " + rec.ToString() + " / " + total.ToString() + " KB";
pb.Value = e.ProgressPercentage;
};
AsyncCompletedEventHandler dfc = null; dfc = (s, e) =>
{
down.DownloadProgressChanged -= dpc;
down.DownloadFileCompleted -= dfc;
CompressionEngine.Current.Decoder.DecodeIntoDirectory(AppDomain.CurrentDomain.BaseDirectory + "/" + i + ".7z", AppDomain.CurrentDomain.BaseDirectory);
File.Delete(fn);
if (i == ServID)
{
button1.Enabled = true;
label1.Text = "Game Is Up-To-Date.Have Fun!!";
label2.Text = "Done..";
}
down.Dispose();
};
My only problam now is when the program is extarting the downloaded file
CompressionEngine.Current.Decoder.DecodeIntoDirectory(AppDomain.CurrentDomain.BaseDirectory + "/" + i + ".7z", AppDomain.CurrentDomain.BaseDirectory);
In some files its take time to extarct the downloaded file
so how i can tell the program to wait until decompressing is complete?
Try defining a single lambda that will encapsulate a single async download and then call that in a loop.
Here's the lambda:
Action<int> downloadFileAsync = i =>
{
var bd = AppDomain.CurrentDomain.BaseDirectory;
var fn = bd + "/" + i + ".7z";
var wc = new WebClient();
DownloadProgressChangedEventHandler dpc = (s, e) =>
{
progressBar1.Value = e.ProgressPercentage;
};
AsyncCompletedEventHandler dfc = null;
dfc = (s, e) =>
{
wc.DownloadProgressChanged -= dpc;
wc.DownloadFileCompleted -= dfc;
CompressionEngine.Current.Decoder.DecodeIntoDirectory(fn, bd);
File.Delete(fn);
wc.Dispose();
};
wc.DownloadProgressChanged += dpc;
wc.DownloadFileCompleted += dfc;
wc.DownloadFileAsync(new Uri(Dlpath + i + "/" + i + ".7z"), fn);
};
You'll note that it nicely detaches all events and also correctly disposes of the WebClient instance.
Now call it like this:
while (i <= ServID)
{
downloadFileAsync(i);
i++;
}
You'll have to fiddle with the progress bar update to properly show the progress of all the files downloading, but in principle this should work for you.
I need to monitor some system events like shutdown, logoff, lock etc.
Now I have 2 questions:
How can I do something before the system get shutdowned, logged off or something like that?
When the process get killed via taskmanager do I have any chance todo something before it get closed, without a second process? Probably not or? (not so important)
What I have so far:
public MainWindow()
{
InitializeComponent();
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
SystemEvents.SessionEnded += SystemEvents_SessionEnded;
SystemEvents.EventsThreadShutdown += SystemEvents_ThreadShutdown;
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
}
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
if(e.Mode == PowerModes.Suspend)
{
Thread.Sleep(5000);
Log("PowerMode Suspend: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
else if(e.Mode == PowerModes.Resume)
{
Thread.Sleep(5000);
Log("PowerMode Resume: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
}
private void SystemEvents_ThreadShutdown(object sender, EventArgs e)
{
Thread.Sleep(5000);
Log("EventThread Shutdown: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
if (e.Reason == SessionSwitchReason.SessionLock)
{
Thread.Sleep(5000);
Log("Locked the machine: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
else if (e.Reason == SessionSwitchReason.SessionUnlock)
{
Thread.Sleep(5000);
Log("Unlocked the machine: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
else if (e.Reason == SessionSwitchReason.SessionLogoff)
{
Thread.Sleep(5000);
Log("Logged of the machine: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
}
private void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
{
if (e.Reason == SessionEndReasons.SystemShutdown)
{
Thread.Sleep(5000);
Log("Shutdown of the machine: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
else if (e.Reason == SessionEndReasons.Logoff)
{
Thread.Sleep(5000);
Log("Logoff of the machine: " + DateTime.Now.ToString("HH:mm:ss") + "\r\n");
}
}
The sleep just should emulate some actions todo before this events.
Only the Windows Lock & Window Closed does work, the other ones not, probably because the program is already closed.
Any idea how I could fix that?
I'm trying to access the Script class that is in the code block below in the event triggered when a file download is completed. How would I be able to do that?
public void DownloadScript(Script script, string DownloadLocation)
{
AddLog(GenerateLog("Downloading Script", "Started", "Downloading " + script.Name + " from " + script.DownloadURL + "."));
WebClient Client = new WebClient();
Client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(Client_DownloadFileCompleted);
Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
Client.DownloadFileAsync(new Uri(script.DownloadURL), DownloadLocation + "test1.zip");
}
Here is the event that is triggered.
public void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error.Message != string.Empty)
{
AddLog(GenerateLog("Downloading Script", "Error", "There was an error downloading " + script.Name + " from " + script.DownloadURL + ". " + e.Error.Message));
Console.WriteLine("Error");
}
else
{
AddLog(GenerateLog("Downloading Script", "Done", "Finished downloading " + script.Name + " from " + script.DownloadURL + "."));
Console.WriteLine("Done");
}
}
You can use a lambda expression to capture the Script object and pass it along to the handler as an extra parameter.
public void DownloadScript(Script script, string DownloadLocation) {
...
WebClient Client = new WebClient();
Client.DownloadFileCompleted += (sender, e) => Client_DownloadFileCompleted(
sender,
e,
script);
}
public void Client_DownloadFileCompleted(
object sender,
AsyncCompletedEventArgs e,
Script script) {
...
}
Ok, in my app there are times when loading the DataGridView can take a minute or two. What I want to do is show a GIF in a form with no border until it reaches the end of the loading function. However, if I do:
Views.Loading ldw = new Views.Loading();
ldw.Show();
...
ldw.Close();
...it never actually draws it to the screen and I can't see it. If I do ShowDialog(), it shows the window but never gets past that line of code. I have a feeling it's because it's not a background worker or because the focus gets set back to the parent because of processing...I don't know.
My form is a blank form, added a picture box, added a gif to the picture box, and made FormBorderStyle = none. Any and all help is appreciated.
Update: Current (non-working) Code
private void InitializeBackgroundWorker()
{
//Defines the DoWork Event Handler for _backgroundWorker.
_bgWorkerReports.DoWork += new DoWorkEventHandler(bgWorkerReports_DoWork);
//Defines the RunWorkCompleted Event Handler for _backgroundWorker.
_bgWorkerReports.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorkerReports_RunWorkerCompleted);
}
private void bgWorkerReports_DoWork(object sender, DoWorkEventArgs e)
{
ldw.Show();
try
{
string strFilter = "";
if (!_strSearchFilter.Equals(""))
{
strFilter += strFilter.Equals("") ? " " + _strSearchFilter : " and " + _strSearchFilter;
}
if (tvFigure.Nodes.Count > 0)
{
if (_strFigureFilter == "ALL")
{
strFilter += " " + Constants.GetColumnName("Figure") + " LIKE '%%' ";
}
else if (!_strFigureFilter.Equals("") && !_strFigureFilter.Equals(tvFigure.TopNode.Name))
{
if (_strSearchFilter.Equals("") || !cbCurrentFigure.Checked)
{
strFilter += strFilter.Equals("") ? " " + Constants.GetColumnName("Figure") + "='" + _strFigureFilter + "'" : " and " + Constants.GetColumnName("Figure") + "='" + _strFigureFilter + "'";
}
}
}
if (!_strIndentureFilter.Equals(""))
{
strFilter += strFilter.Equals("") ? " " + _strIndentureFilter : " and " + _strIndentureFilter;
}
if (!_strReportFilter.Equals(""))
{
strFilter += (!strFilter.Equals("") ? " and" : "") + " part_id in (" + _strReportFilter + ")";
}
if (strFilter.Length > 0)
{
BindingSource bSource = new BindingSource();
bSource.DataSource = _dataController.PopulateDataGrid(_nViewMode, strFilter).Tables[0];
//Set DataSource to bindingSource for DataGridView.
if (_lstValidationResults.Count > 0)
{
dgvParts.DataSource = _lstValidationResults;
foreach (DataGridViewColumn dc in dgvParts.Columns)
{
dc.DataPropertyName = "ErrorMessage";
dc.Visible = true;
dc.SortMode = DataGridViewColumnSortMode.Programmatic;
dc.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
}
dgvParts.AutoResizeColumns();
return;
}
else if (!string.IsNullOrEmpty(_strFigureFilter))
{
dgvParts.DataSource = bSource;
dgvParts.Columns[0].Visible = false;
dgvParts.Columns["Description"].Resizable = DataGridViewTriState.False;
dgvParts.Columns["Description"].Width = 750;
}
// Automatically resize the visible rows.
foreach (DataGridViewColumn col in dgvParts.Columns)
{
col.SortMode = DataGridViewColumnSortMode.Automatic;
if (col.Name != "Description")
{
dgvParts.AutoResizeColumn(col.Index);
}
}
dgvParts.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
// Hide the ToolTips for all the cells - redisplay if there is a report.
dgvParts.ShowCellToolTips = true;
// Set the dataGridView control's border.
dgvParts.BorderStyle = BorderStyle.Fixed3D;
// Get and set the ipb_number to the label.
string ipb_number = _dataController.IPBNumber;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void bgWorkerReports_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
ldw.Close();
this.Cursor = Cursors.Default; //Throws error (Cross-thread)
FormatCells();
BuildColumnsComboBox();
int nTotalCount = 0;
foreach (ListViewItem lvi in listView1.Items)
{
int nCount = _lstReportRecords.Where(rr => lvi.Text.Contains(rr.Description)).Count();
nTotalCount += nCount;
lvi.Text = (lvi.Text.Contains("(") ? lvi.Text.Substring(0, lvi.Text.IndexOf("(") + 1) : lvi.Text.Trim() + " (") + nCount.ToString() + ")";
}
rbAllReports.Text = (rbAllReports.Text.Contains("(") ? rbAllReports.Text.Substring(0, rbAllReports.Text.IndexOf("(") + 1) : rbAllReports.Text + " (") + nTotalCount.ToString() + ")";
int nTaggedCount = _lstReportRecords.Where(rr => rr.Description.Contains("Tagged")).Count();
rbTaggedRecords.Text = (rbTaggedRecords.Text.Contains("(") ? rbTaggedRecords.Text.Substring(0, rbTaggedRecords.Text.IndexOf("(") + 1) : rbTaggedRecords.Text + " (") + nTaggedCount.ToString() + ")";
}
Ideally you would have two threads: the GUI thread and the working thread (which can be a BackgroundWorker). Create and show the window in the GUI thread. Handle the loading in the BackgroundWorker's DoWork event. When the loading is done you can call Close() on the load window from the RunWorkerCompleted event and dispose of it.
LoadWindow loadWindow = new LoadWindow();
loadWindow.TopMost = true; // make sure it doesn't get created behind other forms
loadWindow.Show();
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
void worker_DoWork(object sender, DoWorkEventArgs e)
{
// do your loading here
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// set DataGridView datasource here
...
// close loading window
loadWindow.Close();
}
The problem you might have with displaying the window could be from the TopMost property, which must be set to true. You can also try calling BringToFront() on the loading window after you've created and shown it.
Yes, BackgroundWorker is for exactly this type of purpose. A couple things to add:
Do not interact with the UI in the worker_DoWork event as it is running on a background thread. Set e.Result when you're finished, which you can check from the RunWorkerCompleted event - or use a form-level variable.
Let any exceptions fall through in the worker_DoWork event and you will see them in the worker_RunWorkerCompleted event in e.Error.
If you need the ability to cancel your load, set worker.WorkerSupportsCancellation and check the e.Cancel while in your DoWork event, then you can check e.Cancelled in your RunWorkerCompleted event.
You should call .Dispose() on your BackgroundWorker when finished.
You'll have to run the code to fill the grid on another thread. Something like:
// Set the picturebox loading state, resize the form etc.
PictureBox.SetLoadingImage();
// Initialize a new thread
Thread t = new Thread(new ThreadStart(() =>
{
// Fill the gridview here
GridView1.DataSource = FillWithData();
GridView1.DataBind();
// When finished, reset the picturebox on it's own thread
PictureBox.Invoke((MethodInvoker)(()=> PictureBox.ClearLoadingImage() ));
}));
// Run the thread.
t.Start();