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 6539813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:54:13+00:00 2026-05-25T10:54:13+00:00

I have just created a small program, nothing fancy, in C# that opens an

  • 0

I have just created a small program, nothing fancy, in C# that opens an rdp file. It then goes into an infinite loop and keeps checking if mstsc is running, if it is then it does nothing, if it isn’t (user has closed the session), it re – opens. I ran the code below and it hammered my CPU and then shortly after blue screened, minidump says it was because “This indicates that an exception happened while executing a routine that transitions from non-privileged code to privileged code.”

Not sure what this means, but any ideas what is wrong with this code?

static void Main(string[] args)
{
    RDP();
    for (int i = 1; i > 0; i++)
    {
        foreach (Process clsProcess in Process.GetProcesses())
        {
            if (clsProcess.ProcessName.Contains("mstsc.exe"))
            {
            }
            else
            {
                RDP();
            }
        }
    }
}

private static void RDP()
{
    Process rdp = new Process();
    rdp.StartInfo = new ProcessStartInfo("C:\\Alistair\\Default.rdp");
    rdp.Start();
}

Update: I thought that the processing power needed for the infinite loop might have been to blame but I tried looping for 5 times but same result.

  • 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-25T10:54:14+00:00Added an answer on May 25, 2026 at 10:54 am
    static void Main(string[] args)
    {
        RDP();
        while(true)
        {
            if(Process.GetProcessesByName("mstsc").Length == 0)
                RDP();
            Thread.sleep(300); // Use any value which is confortable with you're request
        }
    }
    
    private static void RDP()
    {
        Process rdp = new Process();
        rdp.StartInfo = new ProcessStartInfo("C:\\Alistair\\Default.rdp");
        rdp.Start();
    }
    

    Here is a portion of code optimised, and it will not hang your CPU at 100 %.

    What you can do is to check the Process event onExit(not sure), or just check rdp.HasExited if true than restart.

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

Sidebar

Related Questions

I have created a small program which logs text data to a file on
I have created a small FTP program, it's just for my own use, so
I'm trying to debug the MSBuild Customtask, that I have just created, but for
I have a program that listens on a port waiting for a small amount
I have just created a AdHoc distribution provisioning profile for the app id 49776ZQRBG.com.gfeed.ride
I have just created a report in Report Manager using a Stored Procedure which
i have just created a drum app. The user taps on the individual buttons
I have just created a GIT on a folder. I now want to add
I have just created 2 pointers which has undefined behavior and try to invoke
Just starting out in asp.net. Have just created a login.aspx page in my site

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.