Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 926825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:45:04+00:00 2026-05-15T19:45:04+00:00

I have problem with win application when more then one network cards is plugged

  • 0

I have problem with win application when more then one network cards is plugged What can i do?

This is the error:

System.InvalidOperationException: Instance 'Citrix XenServer PV Ethernet Adapter #2' does not exist in the specified Category.
   at System.Diagnostics.CounterDefinitionSample.GetInstanceValue(String instanceName)
   at System.Diagnostics.PerformanceCounter.NextSample()
   at System.Diagnostics.PerformanceCounter.NextValue()
   at CurrencyApp.Converter.timerMemProcNetwork_Tick(Object sender, EventArgs e)
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

whole app code:

public partial class Converter : Form
{
    #region Properties

    private int NumOfRepeats;
    private int NumberOfErrorRows;
    private int NumberOfUpdatedRows;
    private int NumberofNewRows;
    private string Status;
    private PerformanceCounter counterReceived;
    private PerformanceCounter counterSent;
    private PerformanceCounter cpuCounter;
    private int nByteCountReceive;
    private int nByteCountSend;
    private int nCPUUsage;
    private int nFirstTimeCheckConnection;
    private float nFreeMemory;
    private PerformanceCounter ramCounter;

    private int ByteCountReceive
    {
        get { return nByteCountReceive; }
        set
        {
            nByteCountReceive = value;
            statusBarPanelByteReceive.Text = "Receive:" + Commas(nByteCountReceive/1024 + 1) + " KB";
        }
    }

    private int ByteCountSend
    {
        get { return nByteCountSend; }
        set
        {
            nByteCountSend = value;
            statusBarPanelByteSend.Text = "Send:" + Commas(nByteCountSend/1024 + 1) + " KB";
        }
    }

    private float FreeMemory
    {
        get { return nFreeMemory; }
        set
        {
            nFreeMemory = value;
            statusBarPanelMem.Text = nFreeMemory + " Mb Available";
        }
    }

    private int CPUUsage
    {
        get { return nCPUUsage; }
        set
        {
            nCPUUsage = value;
            statusBarPanelCPU.Text = "CPU usage " + nCPUUsage + "%";
        }
    }

    private static IDaoFactory DaoFactory
    {
        get { return new NHibernateDaoFactory(ConfigurationManager.AppSettings["NHibernateConfigPath"]); }
    }

    #endregion

    #region Methods

    public Converter()
    {
        InitializeComponent();
        InitialiseCounterRamNetwork();
        InitializeBackgroundWorker();
    }

    [DllImport("wininet")]
    private static extern int InternetGetConnectedState(ref int lpdwFlags, int dwReserved);

    [DllImport("wininet")]
    private static extern int InternetAutodial(int dwFlags, int hwndParent);

    private static string InternetGetConnectedStateString()
    {
        string strState = "";
        try
        {
            int nState = 0;
            // check internet connection state
            if (InternetGetConnectedState(ref nState, 0) == 0)
                return "You are currently not connected to the internet";
            if ((nState & 1) == 1)
                strState = "Modem connection";
            else if ((nState & 2) == 2)
                strState = "LAN connection";
            else if ((nState & 4) == 4)
                strState = "Proxy connection";
            else if ((nState & 8) == 8)
                strState = "Modem is busy with a non-Internet connection";
            else if ((nState & 0x10) == 0x10)
                strState = "Remote Access Server is installed";
            else if ((nState & 0x20) == 0x20)
                return "Offline";
            else if ((nState & 0x40) == 0x40)
                return "Internet connection is currently configured";

            // get current machine IP
            string strHostName = Dns.GetHostName();
            string ip = "/";

            IPAddress[] addrs = Dns.GetHostAddresses(strHostName);
            foreach (var addr in addrs)
            {
                if (addr.AddressFamily.ToString() == "InterNetwork")
                {
                    ip = addr.ToString();
                }
            }
            strState += ",  Machine IP: " + ip;
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }

        return strState;
    }

    private void ConnectionInfo()
    {
        try
        {
            int nState = 0;
            if (InternetGetConnectedState(ref nState, 0) == 0)
            {
                if (nFirstTimeCheckConnection++ == 0)
                    // ask for dial up or DSL connection
                    if (InternetAutodial(1, 0) != 0)
                        // check internet connection state again
                        InternetGetConnectedState(ref nState, 0);
            }
            if ((nState & 2) == 2 || (nState & 4) == 4)
                // reset to reask for connection agina
                nFirstTimeCheckConnection = 0;

            statusBarPanelInfo.Text = InternetGetConnectedStateString();
        }
        catch (Exception ex)
        {
            statusBarPanelInfo.Text = ex.ToString();
        }
    }

    private void InitialiseCounterRamNetwork()
    {
        cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
        ramCounter = new PerformanceCounter("Memory", "Available MBytes", true);
        string instance = "MS TCP Loopback interface";

        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

        foreach (NetworkInterface nic in nics)
        {
            if (nic.Description == "MS TCP Loopback interface")
                continue;

            if (nic.OperationalStatus.ToString() == "Up")
            {
                instance = nic.Description;
                break;
            }
        }

        counterReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance);
        counterSent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance);
    }

    private void btnStartCurrencyConverter_Click(object sender, EventArgs e)
    {
        NumOfRepeats = 0;
        NumberOfErrorRows = 0;
        NumberofNewRows = 0;
        NumberOfUpdatedRows = 0;
        txtStatus.Text = "Start: " + DateTime.Now + Environment.NewLine;

        lblNumberOfUpdatedRows.Text = NumberOfUpdatedRows.ToString();
        lblNumberofNewRows.Text = NumberofNewRows.ToString();

        btnStartCurrencyConverter.Enabled = false;
        btnCancel.Enabled = true;

        if (!bwCrawler.IsBusy)
            bwCrawler.RunWorkerAsync();
    }

    private static string Commas(int nNum)
    {
        string str = nNum.ToString();
        int nIndex = str.Length;
        while (nIndex > 3)
        {
            str = str.Insert(nIndex - 3, ",");
            nIndex -= 3;
        }
        return str;
    }

    private void InitializeBackgroundWorker()
    {
        bwCrawler.DoWork += bwCrawler_DoWork;
        bwCrawler.ProgressChanged += bwCrawler_ProgressChanged;

        bwCrawler.WorkerReportsProgress = true;
        bwCrawler.WorkerSupportsCancellation = true;
    }

    private void CurrencImport()
    {
        CurrencyConvertorSoapClient client = new CurrencyConvertorSoapClient();

        string[] curr1 = Enum.GetNames(typeof (Currency));
        string[] curr2 = Enum.GetNames(typeof (Currency));
        int i = 0;
        int j = 0;
        int workComplete = curr1.Length*curr2.Length;
        int workDone = 0;
        decimal percentComplete = 0;

        foreach (var c1 in curr1)
        {
            foreach (var c2 in curr2)
            {
                start_of_loop:
                {
                }
                try
                {
                    Currency cEnum1 = (Currency) Enum.Parse(typeof (Currency), c1);
                    Currency cEnum2 = (Currency) Enum.Parse(typeof (Currency), c2);
                    double rate = client.ConversionRate(cEnum1, cEnum2);

                    ICurrenciesDao currenciesDao = DaoFactory.GetCurrenciesDao();

                    Currencies currencyExist = currenciesDao.GetConversionRateByFromCurrencyToCurrency(c1, c2);

                    if (currencyExist != null)
                    {
                        // update if row exist
                        currencyExist.ConversionRate = Convert.ToDecimal(rate);
                        currenciesDao.SaveOrUpdate(currencyExist);
                        currenciesDao.CommitChanges();

                        i++;
                        NumberOfUpdatedRows = i;
                    }
                    else
                    {
                        // write new row
                        Currencies currencyNew = new Currencies(c1, c2, Convert.ToDecimal(rate), DateTime.Now);
                        currenciesDao.Save(currencyNew);
                        currenciesDao.CommitChanges();

                        j++;
                        NumberofNewRows = j;
                    }

                    Status = c1 + " - " + c2 + ": " + rate;
                }
                catch (Exception ex)
                {
                    Thread.Sleep(200000);

                    if (NumOfRepeats > 50)
                    {
                        Status = ex.ToString();
                        NumberOfErrorRows = 1;
                    }
                    else
                        goto start_of_loop;
                }

                if (bwCrawler.CancellationPending)
                    break;

                workDone++;
                percentComplete = (workDone/workComplete)*100;
                bwCrawler.ReportProgress(Convert.ToInt32(percentComplete));
                NumOfRepeats = 0;

                if (percentComplete == 100)
                    break;
            }

            if (bwCrawler.CancellationPending)
                break;

            if (percentComplete == 100)
                break;
        }
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
        if (bwCrawler.IsBusy)
        {
            //Initiate cancel
            bwCrawler.CancelAsync();
        }

        btnCancel.Enabled = false;
        btnStartCurrencyConverter.Enabled = true;

        txtStatus.AppendText("Canceled: " + DateTime.Now + Environment.NewLine);
    }

    private void bwCrawler_DoWork(object sender, DoWorkEventArgs e)
    {
        CurrencImport();
    }

    private void bwCrawler_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        btnCancel.Enabled = false;
        btnStartCurrencyConverter.Enabled = true;

        if (e.Cancelled)
        {
            txtStatus.AppendText("Canceled" + Environment.NewLine);
        }
        else if (e.Error != null)
        {
            txtStatus.AppendText("Error. Details: " + (e.Error) + Environment.NewLine);
        }
        else
        {
            txtStatus.AppendText("Finished: " + DateTime.Now + Environment.NewLine);
        }
    }

    private void bwCrawler_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        if (NumberOfErrorRows > 0)
        {
            if (bwCrawler.IsBusy)
            {
                //Initiate cancel
                bwCrawler.CancelAsync();
            }
        }

        lblNumberOfUpdatedRows.Text = NumberOfUpdatedRows.ToString();
        lblNumberofNewRows.Text = NumberofNewRows.ToString();
        txtStatus.AppendText(Status + Environment.NewLine);

        if (txtStatus.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length > 200)
        {
            txtStatus.Text = string.Empty;
        }
    }

    private void timerConnectionInfo_Tick(object sender, EventArgs e)
    {
        ConnectionInfo();
    }

    private void timerMemProcNetwork_Tick(object sender, EventArgs e)
    {
        FreeMemory = ramCounter.NextValue();
        CPUUsage = Convert.ToInt32(cpuCounter.NextValue());
        ByteCountReceive = Convert.ToInt32(counterReceived.NextValue());
        ByteCountSend = Convert.ToInt32(counterSent.NextValue());
    }

    #endregion
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:45:05+00:00Added an answer on May 15, 2026 at 7:45 pm

    You are reading a performance counter for which you specify an instance it doesn’t exists. Judging from the instance name, you try to read ‘Network Interface’ category. Make sure you read the proper category, on the proper machine. Post your code that initializes the performance counter objects referenced in timerMemProcNetwork_Tick.

    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface nic in nics)
    {
       ...
       counterReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance);
       ...
    }
    

    This code mixes apples and oranges. Use PerformanceCounterCategory.GetInstanceNames on the “Network Interface” category to get the list of valid instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 466k
  • Answers 466k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should be able to do it via WMI. The… May 16, 2026 at 1:42 am
  • Editorial Team
    Editorial Team added an answer I have found the problem that i have not set… May 16, 2026 at 1:42 am
  • Editorial Team
    Editorial Team added an answer You can probably change the Filename function to a sub:… May 16, 2026 at 1:42 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.