.net-4.0

Thread.sleep vs Monitor.Wait vs RegisteredWaitHandle?

此生再无相见时 提交于 2019-12-05 02:30:13
(the following items has different goals , but im interesting knowing how they "PAUSEd") questions Thread.sleep - Does it impact performance on a system ?does it tie up a thread with its wait ? what about Monitor.Wait ? what is the difference in the way they "wait"? do they tie up a thread with their wait ? what about RegisteredWaitHandle ? This method accepts a delegate that is executed when a wait handle is signaled. While it’s waiting, it doesn’t tie up a thread. so some thread are paused and can be woken by a delegate , while others just wait ? spin ? can someone please make things clearer

Conditional compilation for .NET 4 [duplicate]

你说的曾经没有我的故事 提交于 2019-12-05 02:19:39
This question already has answers here : Closed 6 years ago . Possible Duplicate: Conditional compilation and framework targets I have some code that works in .NET 4, but it does not work in .NET 3.5. In .NET 3.5 it requires to use interop calls to Windows. I would like using a "ifdef" to use a different code path in both cases (eventually I will deprecate the .NET 3.5 code). Is there a pre-defined directive value to identify when the code is compiled with .NET 4? Is there a good link with all the predefined directives ( DEBUG , TRACE , etc.)? The page below only gives the directives, but not

DataTable.Load, One or more rows contain values violating non-null, unique, or foreign-key constraints

旧街凉风 提交于 2019-12-05 02:09:05
问题 I searched a lot, but could not find the solution. I get the error: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. I run DataTable.GetErrors() and see that some columns are set to Not NULL in SQL Compact Edition Database. And these columns are used in LEFT OUTER JOIN query so they are null when the query is run. (I can get the results when i run the query in Server Explorer in VS). The error occurs when trying to load the

EF, Code First - How to set a custom Guid identity value on insert

回眸只為那壹抹淺笑 提交于 2019-12-05 01:47:15
I`m facing the following problem when dealing with inserting new entities in the DB that has Guid as primary keys - EF 5 with Code first approach. I know there are a lot similar topics as I was roving for hours for this issue, but I couldn`t find topic with this problem. As an example, my POCO class is: public class EntityRole : IAdminModel { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [Required] [MaxLength(50)] public string Name { get; set; } [Required] [Display(Name = "Role code")] [MaxLength(20)] public string RoleCode { get; set; } [Display

How do I use Console.CancelKeyPress in .NET 4? (Works fine in .NET 3.5 and below)

≯℡__Kan透↙ 提交于 2019-12-05 01:37:40
I am writing a Console app in C# 4 and want to gracefully cancel my program and Ctrl + C is pressed. The following code I have used many times before, but now when trying to use it in .NET 4, it seems a strange unhandled exception is occurring. namespace ConsoleTest { class Program { private static bool stop = false; static void Main(string[] args) { System.Console.TreatControlCAsInput = false; System.Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); while (!stop) { System.Console.WriteLine("waiting..."); System.Threading.Thread.Sleep(1000); } System.Console

WPF DotNET Application will run in debug mode, but .EXE will not run

↘锁芯ラ 提交于 2019-12-05 01:31:45
I wrote a WPF application in C# using VS 2010. The application will run fine in debug mode using Visual Studio, but when I go to run the .EXE from the bin\release folder, nothing happens. I do not get any error messages from windows and there are no errors or warnings in VS. I have tried to build, rebuild and clean the solution (in every possible order) with no luck. My solution contains 2 projects, both of which use .NET 4.0 framework, and I have .NET 4.0 installed on my PC. I have tried on both XP and Win7 and still nothing. I also just noticed that the output from Debug when I run the

Continue Task after all tasks finish

我只是一个虾纸丫 提交于 2019-12-05 01:22:18
问题 In some class I want to load 2 collection asynchronously with Task and stop busyindicator I try Something like this var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); WaitingIndicatorViewModel.IsBusy = true; var loadData1 = new Task<ObservableCollection<Data1>>(GetData1FromService).ContinueWith(t => Data1Collection = t.Result, uiScheduler); var loadData2 = new Task<ObservableCollection<Data2>>(GetData2FromService).ContinueWith(t => Data2Collection = t.Result, uiScheduler);

Parallel.For and Break() misunderstanding?

自闭症网瘾萝莉.ら 提交于 2019-12-05 01:19:43
I'm investigating the Parallelism Break in a For loop. After reading this and this I still have a question: I'd expect this code : Parallel.For(0, 10, (i,state) => { Console.WriteLine(i); if (i == 5) state.Break(); } To yield at most 6 numbers (0..6). not only he is not doing it but have different result length : 02351486 013542 0135642 Very annoying. (where the hell is Break() {after 5} here ??) So I looked at msdn Break may be used to communicate to the loop that no other iterations after the current iteration need be run. If Break is called from the 100th iteration of a for loop iterating

How to fix exception thrown when sending mail message to multiple recipients?

五迷三道 提交于 2019-12-05 01:15:59
In the code snippet below, I'm getting a FormatException on 'this.Recipients'. More specifically, the message is "An invalid character was found in the mail header: ';'". Recipients is a string of three email addresses separated by semicolons (the ';' character). The list of recipients is read from an app.config and the data is making it into the Recipients variable. How can I be getting this error when multiple recipients should be separated by a semicolon? Any suggestions? As always, thanks for your help! public bool Send() { MailMessage mailMsg = new MailMessage(this.Sender, this.Recipients

Wrong exception after calling .net4.0 com server from delphi application

隐身守侯 提交于 2019-12-05 01:03:19
问题 We are migrating our codebase from BDS2006 to Rad Studio XE, and we found some very strange behavior: if we make invalid floating point operation (ie. division by zero) after creating some object from COM server implemented in .Net4.0, we don't get normal exception (ie. EDivisionByZero), but EStackOverflow. We managed to prepare very simple example: ComErrorExample There is an .net 4.0 assembly, with com interface (one function returning string) and simple delphi application: var a, b: Double