My online notes – Section 0003

Note 1: Check if current user is administrator

WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
Console.WriteLine("Programm wird unter dem Usercontext ausgeführt: {0}", principal.Identity.Name);
Console.WriteLine("Adminrechte vorhanden: {0}", principal.IsInRole(WindowsBuiltInRole.Administrator) ? "Ja" : "Nein");

Note 2: ContextMenuStrip at selected row open and Index in DataTable localize.

private void dgv_MouseUp(object sender, MouseEventArgs e)
{
  DataGridView.HitTestInfo hitTest = ((DataGridView)sender).HitTest(e.X, e.Y);

  if (hitTest .Type == DataGridViewHitTestType.Cell)
  {
     dgv.CurrentCell = dgv.Rows[hTest.RowIndex].Cells[hTest.ColumnIndex];
  }
}

Continue reading My online notes – Section 0003

My online notes – Section 0002

Note 1: Wait from GUI Thread

private void cmdStart_Click(object sender, RoutedEventArgs e)
{
	thr = new Thread(new ParameterizedThreadStart(Test));
	thr.Start(this);
}

public void Test(object obj)
{
	var wnd = (MainWindow)obj;
	int i = 0;
	while (true)
	{
		i++;
		if (i % 1000000 == 0) //Ab ca. 1000000 schafft die UI es
		{
			var __op = wnd.Dispatcher.BeginInvoke(new Action(UpdateGUI));
			__op.Wait(); //Magische Methode mit der der Arbeitsthread wartet?!
		}
	}
}

public void UpdateGUI()
{
	Random r = new Random();

	txt.Text = "";
	txt.Text = ((char)r.Next(65, 91)).ToString();
}
		

Continue reading My online notes – Section 0002

My online notes – Section 0001

Note 1:
MongoDB Applied Design Patterns
https://www.dropbox.com/s/5nksr6e8z09mu83/Oreilly.MongoDB.Applied.Design.Patterns.Mar.2013.epub?dl=0

Peopleware
https://www.dropbox.com/s/4v3j51mkt13yusc/Peopleware.epub?dl=0


Note 2:

static PerformanceCounter cpuUsage;
public static void Main(string[] args)
{
	cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
	Timer t = new Timer(new TimerCallback(TimerFunction), null, 0, 500);
	Console.ReadLine();
}

static void TimerFunction(Object stateInfo)
{
	//AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
	Console.WriteLine(cpuUsage.NextValue() + " %");
}

Continue reading My online notes – Section 0001