.net-2.0

.net construct for while loop with timeout

安稳与你 提交于 2019-12-05 09:50:52
问题 I commonly employ a while loop that continues to try some operation until either the operation succeeds or a timeout has elapsed: bool success = false int elapsed = 0 while( ( !success ) && ( elapsed < 10000 ) ) { Thread.sleep( 1000 ); elapsed += 1000; success = ... some operation ... } I know there a couple of way to implement this, but the basic point is that I repeatedly try some operation with a sleep until success or I've slept too long in aggregate. Is there a built-in .net class/method

How do you tell if a Windows Form is open but behind another window?

点点圈 提交于 2019-12-05 09:38:30
Calling Form.Visible will return true regardless of whether the form is maximized, minimized, or has a FormWindowState of Normal. What I want to know is how to tell if the form is open but "hidden" behind another application's window. If that's the case, I want to bring it to the front and actually make it visible to the user. I tried the BringToFront() method but it didn't work. I also tried calling the Show() method but if the form is behind another application's window, it remains that way. The only workaround I found to the problem is setting the Form's FormWindowState to Minimized

What should I use to serialize a DataTable to JSON in ASP.NET 2.0?

橙三吉。 提交于 2019-12-05 08:51:52
I'm trying to support a legacy app I made a year ago and need to use jQuery AJAX calls to get data from the server. I have a JsonHelper class that I use to serialize DataTable s and DataSet s. This normally works fine in .NET 4.0, but .NET 2.0 there is no System.Web.Script.Serialization library and therefore no JavaScriptSerializer class. I've tried to find another JSON serializer, but so far I can't get anything to work. I tried using JSON.NET 2.0 http://json.codeplex.com/releases/view/13099 but it said it needed a higher framework. So I tried JSON.NET 1.3.1 http://json.codeplex.com/releases

Comparing two generic lists on a specific property

Deadly 提交于 2019-12-05 08:00:21
问题 I'm using VB.NET with .NET 2.0. I have two lists, and I want to compare the lists on a specific property in the object, not the object as a whole, and create a new list that contains objects that are in one list, but not the other. myList1.Add(New Customer(1,"John","Doe") myList1.Add(New Customer(2,"Jane","Doe") myList2.Add(New Customer(1,"","") Result in the above example would contain one customer, Jane Doe , because the identifier 2 wasn't in the second list. How can you compare these two

How to distinguish the server version from the client version of Windows?

拈花ヽ惹草 提交于 2019-12-05 07:21:40
How to distinguish the server version from the client version of Windows? Example: XP, Vista, 7 vs Win2003, Win2008. UPD: Need a method such as bool IsServerVersion() { return ...; } Ok, Alex, it looks like you can use WMI to find this out: using System.Management; public bool IsServerVersion() { var productType = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") .Get().OfType<ManagementObject>() .Select(o => (uint)o.GetPropertyValue("ProductType")).First(); // ProductType will be one of: // 1: Workstation // 2: Domain Controller // 3: Server return productType != 1; } You'll

The right data structure to use for an Excel clone

倖福魔咒の 提交于 2019-12-05 05:12:25
问题 Let say I'm working on an Excel clone in C#. My grid is represented as follows: private struct CellValue { private int column; private int row; private string text; } private List<CellValue> cellValues = new List<CellValue>(); Each time user add a text, I just package it as CellValue and add it into cellValues. Given a CellValue type, I can determine its row and column in O(1) time, which is great. However, given a column and a row, I need to loop through the entire cellValues to find which

Reading a large number of files quickly

故事扮演 提交于 2019-12-05 04:54:32
I have a large number of (>100k) relatively small files (1kb - 300kb) that I need to read in and process. I'm currently looping through all the files and using File.ReadAllText to read the content, processing it, and then reading the next file. This is quite slow and I was wondering if there is a good way to optimize it. I have already tried using multiple threads but as this seems to be IO bound I didn't see any improvements. You're most likely correct - Reading that many files is probably going to limit your potential speedups since the Disk I/O will be the limiting factor. That being said,

Separate threads in a web service after it's completed

房东的猫 提交于 2019-12-05 04:00:26
问题 If this has been asked before my apologies, and this is .NET 2.0 ASMX Web services, again my apologies =D A .NET Application that only exposes web services. Roughly 10 million messages per day load balanced between multiple IIS Servers. Each incoming messages is XML, and an outgoing message is XML. (XMLElement) (we have beefy servers that run on steroids). I have a SLA that all messages are processed in under X Seconds. One function, Linking Methods, in the process is now taking 10-20 seconds

Converting Unicode string to unicode chars in c# for indian languages

江枫思渺然 提交于 2019-12-05 03:34:28
I need to convert unicode string to unicode characters. for eg:Language Tamil "கமலி"=>'க','ம','லி' i'm able to strip unicode bytes but producing unicode characters is became problem. byte[] stringBytes = Encoding.Unicode.GetBytes("கமலி"); char[] stringChars = Encoding.Unicode.GetChars(stringBytes); foreach (var crt in stringChars) { Trace.WriteLine(crt); } it gives result as : 'க'=>0x0b95 'ம'=>0x0bae 'ல'=>0x0bb2 'ி'=>0x0bbf so here the problem is how to strip character 'லி' as it as 'லி' without splitting like 'ல','ி'. since it is natural in Indian language by representing consonant and vowel

How do I determine which monitor my winform is in?

十年热恋 提交于 2019-12-05 02:52:29
I have been up and down this site and found a lot of info on the Screen class and how to count the number of monitors and such but how do I determine which montitor a form is currently in? A simpler method than using the bounds is to use the Screen.FromControl() method. This is the same functionality that Windows uses. Screen.FromControl(this) will return the screen object for the screen that contains most of the form that you call it from. This should do the trick for you: private Screen FindCurrentMonitor(Form form) { return Windows.Forms.Screen.FromRectangle(new Rectangle( _ form.Location,