Chitika

Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Tuesday, February 12, 2013

C# Cross thread GUI update issue

Following is the pattern to handle C# cross thread GUI update issue (ref: stackoverflow)


delegate void SetTextCallback(string text);

private void SetText(string text)
{
  // InvokeRequired required compares the thread ID of the
  // calling thread to the thread ID of the creating thread.
  // If these threads are different, it returns true.
  if (this.textBox1.InvokeRequired)
  { 
    SetTextCallback d = new SetTextCallback(SetText);
    this.Invoke(d, new object[] { text });
  }
  else
  {
    this.textBox1.Text = text;
  }
}

Monday, February 11, 2013

debug c++ activeX control of different project

Sometimes solutions are big, consisting of different project. When we have to debug these projects we get the notification that: Breakpoint will not currently be hit. No symbol loaded for this document.

To debug such project, following are the steps:

  1. Clean solution
  2. Rebuild solution
  3. Run the executable project (by setting it as startup project)
  4. When the said activeX just launched by the executable, go to debug and attach to the executable containing the activeX
  5. now, easily debug the activeX project.

Wednesday, February 6, 2013

Editing dot net resource .resx file

.Net Resource Editors are third party programs/freewares, which could be used to edit resource files (having extension .resx).

Following is similar utility:

http://fishcodelib.com/files/ResourceNet2.zip

C# get fully qualified domain name

Use following code snippet to get fully qualified domain name of current machine:



string domainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
string hostName = Dns.GetHostName();
string fqdn = "";

if (!hostName.Contains(domainName))
    fqdn = hostName + "." + domainName;
else
    fqdn = hostName;

C# Auto detect default IP Address


Use following code snippet to automatically detect the default IP address:



  IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
                    if (localIPs != null &&
                        localIPs.Length > 0)
                    {
                        tbServerName.Text = (from localIP in localIPs
                                             where localIP.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
                                             select localIP.ToString()).FirstOrDefault();
                    }
                    else
                    {
                        tbServerName.Text = "";
                    }