.net-2.0

Check if date range is sequential in c#?

爷,独闯天下 提交于 2019-12-03 12:17:59
Assume I have a user interface where the user can select days. Is there a way to check if the days selected are sequential, such as: 4/4, 4/5, 4/6, 4/7, 4/8, 4/9, 4/10 or 4/29, 4/30, 5/1, 5/2, 5/3 I know I probably can loop through the date range and check, but I was more curious if there was a built in method already to check for this. Regarding the above scenarios, they are in order and they can roll over into the next month. I am using the .NET Framework 2.0 and can't use LINQ. Regarding Tom's answer: DateTime dtStart = new DateTime(2011,5,4); DateTime dtEnd = new DateTime(2011,5,11); int

Randomly occurring AccessViolationException in GDI+

拜拜、爱过 提交于 2019-12-03 11:50:50
问题 We've got the problem that sometimes an AccessViolationException occurs and a simple group box gets drawn with white background and a red cross on top of it. We can't reproducable this bug reliably, it just occurs from time to time. We don't do anything special, we're just showing a main window with a menu, toolbar, the group box on the main panel and some hyperlink controls inside the group box. From the stack trace it seems to be a bug in Windows Forms or GDI+: System

Invoke() is blocking

丶灬走出姿态 提交于 2019-12-03 10:04:42
From time to time my applications GUI stops redrawing. There a lot of threads that are firing all kinds of events (like timers or network data ready etc.). Also there are a lot of controls that are subscribing these events. Because of that, all the event handlers play the InvokeRequired/Invoke game. Now I figured out that when the GUI freezes a lot of threads are waiting for Invoke() to return. Looks like the message pump stopped pumping. The handlers look like this: private void MyEventHandler( object sender, EventArgs e ) { if ( InvokeRequired ) { Invoke( new EventHandler( MyEventHandler ),

How do you provide a default type for generics?

戏子无情 提交于 2019-12-03 09:29:50
I have a class that currently has several methods that take integer parameters. These integers map to operations that the application can perform. I'd like to make the class generic so that the consumers of the class can provide an enum type that they have with all the operations in it, then the methods will take parameters of that enum type. However, I want them to be able to not specify a generic type at all, and have it default back to integers with no change in syntax from the current way. Is this possible? You can't do it in the definition of the class: var foo = new MyGenericClass(); //

Allow wake timers Windows 7/Vista

懵懂的女人 提交于 2019-12-03 09:06:55
I need to allow WakeTimers (computer wake up from sleep/hibernation) for all power plans set on plugged in to Enabled. I tried Win32_PowerSetting but it only works on english version of Windows. I need to use .NET 2.0 Thanks for responses ! I suspect you can do this using API calls to powrprof.dll, as well as WMI, but I haven't had the time to figure that approach out. This setting appears to be simply a boolean registry key that is located according to your current power plan: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\(Current Power Scheme GUID)\(Sleep

Why not upgrade to the latest .NET framework?

为君一笑 提交于 2019-12-03 08:58:15
问题 I see a lot of people have .NET 2.0 or even 1.1 as a requirement for their projects. In my own workplace there is also lots of skepticism for upgrading to the latest and greatest .NET framework. As a programmer I feel it is very frustrating working with the older frameworks when you know that you could have done this so much easier with the newer frameworks. I usually install beta versions and play with them so I quickly get familiar with them and in the process forget the old way of doing

C# docking control library

人走茶凉 提交于 2019-12-03 08:50:30
I'm looking for a docking control library for C# WinForms that works in NET 2.0, is freeware, doesn't use any P/Invokes (so that it's compatible with Mono) and isn't buggy. WeifenLuo would have been the best option here, but because it uses a ton of P/Invokes, I will never be able to get my software to be cross-platform. So any good suggestions? rayanisran I managed to get WeifenLuo's docking library control (DockPanel Suite) working on Mono, at the cost of some features. If anyone is interested, please read this. You could take a look at SharpDevelop , but I can't say whether it uses P/Invoke

How does default/relative path resolution work in .NET?

◇◆丶佛笑我妖孽 提交于 2019-12-03 08:10:22
So... I used to think that when you accessed a file but specified the name without a path (CAISLog.csv in my case) that .NET would expect the file to reside at the same path as the running .exe. This works when I'm stepping through a solution (C# .NET2.* VS2K5) but when I run the app in normal mode (Started by a Websphere MQ Trigger monitor & running in the background as a network service) instead of accessing the file at the path where the .exe is it's being looked for at C:\WINDOWS\system32. If it matters The parent task's .exe is in almost the same folder structure/path as my app I get a

SerialPort.GetPortNames() returns incorrect port names

人盡茶涼 提交于 2019-12-03 07:58:23
While c# is not my primary programming language, I'm maintaining such a program for a couple of years now. This program connects to a device on a serial port and works from Windows XP up to 8.1. One specific "feature" is that it uses .NET Framework 2.0. With some users upgrading to Windows 10 we've got complains that the program cannot detect/open the COM port of the device. We have confirmed this on our own test systems with clean Win10 installation. It turns out that the function SerialPort.GetPortNames() returns incorrect port names and adds 'strange' characters after the port name. For

Output to command-line if started from command line

你。 提交于 2019-12-03 07:43:22
I'm writing an application that can be started either as a standard WinForms app or in unattended mode from the command-line. The application was built using the VS 2k5 standard WinForms template. When the application is executed from the command-line, I want it to output information that can be captured by the script executing the application. When I do this directly from Console.WriteLine(), the output does not appear, although it can be captured by piping to a file. On the other hand, I can force the application to pop up a second console by doing a P/Invoke on AllocConsole() from kernel32.