• 0

[C#] Debug mode works, Start without debugging fails


Question

I have an app which works great (and as expected) when I start and run it in debug mode in VS 2008 Pro. However, when I try to "Start without debugging", the app is a bust. Here's what happens:

  1. I start the program
  2. I start the main part of my program by pushing a button
  3. The operations seem to work fine for a second, but then they don't stop when expected.
  4. Instead, the app starts using nearly 100% of the CPU and when I close it ("X" button) it still keeps running. I have to kill it through the Task Manager.

I'm not sure how to debug this, since (ahhh!) I'm running it without debugging!

Does anyone know how to debug this or has anyone faced similar circumstances? I've looked online and have found next to nothing.

19 answers to this question

Recommended Posts

  • 0

Yes, it does take 100% CPU from the debug folder. This is actually how I originally saw the problem, because I didn't want to load VS to run the program, so I tried running the exe from the debug folder and noticed the problem. Does this information suggest a certain problem?

  • 0

I have this in one of the threads:

		private void ....
		{
				.....
				WaitFor(4);
				.....
		}

		private void WaitFor(double seconds)
		{
			DateTime t = DateTime.Now.AddSeconds(seconds);
			while (DateTime.Now < t)
			{
				Application.DoEvents();
			}
		}

I know this isn't great design, but needless to say events don't easily work in this situation so I'm stuck with this for now. Could this be causing the 100% CPU usage or cause the app to hang (for more than 4 seconds) and not work?

Thanks for your continued help :-)

  • 0

Actually, it's not my thread loop. It's in one of the threads that is running. Can you explain why I should use Sleep() instead of using "busy waiting + Application.DoEvents()"? I'm not quite sure what you're getting at.

I tried your suggestion and it breaks my application as I need the program running and "doing events", but I still need to wait for some amount of time. If I can avoid it, I don't want to have to wire up events as it will mean re-writing a good amount of my code. Any more ideas :-)

  • 0

		private void ....
		{
				.....
				WaitFor(4);
				.....
		}

		private void WaitFor(double seconds)
		{
			DateTime t = DateTime.Now.AddSeconds(seconds);
			while (DateTime.Now < t)
			{
				Application.DoEvents();
				Thread.Sleep(1);
			}
		}

Try this way. It should do events and not waste 100% CPU.

  • 0

Application.DoEvents() doesn't wait if there's nothing the Application engine needs to do. Put the Thread.Sleep() in and you should be good. It sounds like your background thread is eating up all the time. (I usually use Thread.Sleep(500) but I guess 1 should work ok.)

You can also use a System.Timer to call a delegate after the elapsed time.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Never had any issues with the MS Store either. But ymmv and N=1 etc.
    • I am sure the 17 people that actually do it will like it.
    • I've noticed stutters and hitching in this. Unreal has yet to convince me. So far, idTech 8 engine used in Doom The Dark Ages is by far the most beautiful and hyper optimized engine I've seen to date. Period. Its instantaneous load times and absolutely zero stutter gameplay is just next level.
    • As Windows 10 support winds down, KDE welcomes "Windows 10 exiles" to Linux by David Uzondu Early last month, we reported on a Linux (KDE)-backed initiative called "End of 10," which aimed to show folks how to save their unsupported Windows 10 PCs by installing Linux. Now, as we speed towards October 14, 2025, end-of-support date for Windows 10, KDE is still urging, or rather, inviting what it calls "Windows 10 exiles" to consider making the switch. KDE's message is pretty blunt: your Windows 10 computer is about to become "junk" and "officially obsolete" once Microsoft pulls the plug on support. The organization paints a grim picture of unpatched bugs leading to increased risks of being hacked, potentially compromising your data and identity. Beyond security, KDE suggests that new versions of applications will cease to run, and Microsoft will effectively block upgrades to newer Windows versions unless you purchase new hardware. KDE calls this "tech extortion" and points to the environmental impact of discarded PCs. The alternative presented is to "upgrade the smart way" by keeping existing hardware and installing Linux, specifically highlighting its Plasma desktop, which it claims can run well even on machines a decade old. To entice users, KDE details why Plasma could be a good fit. The environment aims for a familiar feel, with a launch menu and workspace akin to what Windows users are accustomed to, but also offers extensive customization to mimic Windows, macOS, or create something entirely unique. Being open source and developed by a nonprofit, Plasma is free. KDE also points to powerful features like multiple virtual desktops and the Dolphin file manager's built-in connectivity tools for servers and cloud services. Recognizing that switching operating systems is a significant step, KDE offers advice for the transition. It concedes Linux "does take some getting used to" and encourages new users to lean on the community for help. A key piece of advice is not to expect the exact same Windows programs but to look for Linux applications that perform similar functions, noting that essentials like Firefox and LibreOffice often come pre-installed. For additional software, KDE points to package managers like its Discover application, which acts as an app store. KDE also outlines what it believes users will not miss from Windows, such as viruses, ads injected into the operating system, spyware, forced updates, and mandatory account registrations. Interestingly, this "What will you miss" section, while focusing on shedding unwanted Windows behaviors, didn't mention the real things you'd also miss, like the full Adobe Creative Suite, specific Microsoft Office desktop applications, or popular titles like Call of Duty and Fortnite, which are often unsupported due to anti-cheat systems that don't work on Linux. If this all sounds good to you, the most straightforward way to get started is by downloading a Linux distribution (or "distro") that comes with KDE Plasma as its default desktop environment. A few good options include Kubuntu, Fedora KDE Spin, openSUSE, and KDE Neon. But as KDE notes, Plasma isn't your only option. Other desktop environments exist, like GNOME, Xfce, and Cinnamon.
    • Looks exactly as i expected minus horrific "pop in" you get from UE. The framerate of video was horrid or the game was full of blur hope that sorted or can be taken off on PC. The Vibrance also seems to be upped very high.
  • Recent Achievements

    • Week One Done
      Jim Dugan earned a badge
      Week One Done
    • Week One Done
      Adam Todd earned a badge
      Week One Done
    • Contributor
      Ed B went up a rank
      Contributor
    • One Month Later
      moporcho earned a badge
      One Month Later
    • One Month Later
      Parotel earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      212
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      134
    4. 4
      Xenon
      119
    5. 5
      +FloatingFatMan
      113
  • Tell a friend

    Love Neowin? Tell a friend!