.net-4.0

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

孤街浪徒 提交于 2019-12-22 03:49:10
问题 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 (

Can I get a path for a Memory Mapped File? (.NET 4.0)

会有一股神秘感。 提交于 2019-12-22 02:56:32
问题 I want that a non-.NET application access a Memory Mapped file, but this application is not aware of the existence of Memory Mapped files , so I need the file path. It is possible? 回答1: They have some samples here. EDIT I think this would provide the answer. Basically, it would seem some sort of memory pointer is required for memory-mapped files, and not a file system path. 回答2: You can use the GetMappedFileName function to get the path to a memory mapped file when it is mapped. This of

Default for generic type? [duplicate]

我与影子孤独终老i 提交于 2019-12-22 01:46:48
问题 This question already has answers here : Is there a reasonable approach to “default” type parameters in C# Generics? (5 answers) Closed 5 years ago . Is it possible to do something like public class PriorityQueue<TValue, TPriority=int> where TPriority : IComparable (note the =int ) ? Before you suggest it, yes, I know I can just add another line: public class PriorityQueue<TValue> : PriorityQueue<TValue, int> { } But I'm wondering if it's possible to do it as a param. 回答1: No. There is no

Producer Consumer model using TPL, Tasks in .net 4.0

蹲街弑〆低调 提交于 2019-12-22 01:20:53
问题 I have a fairly large XML file(around 1-2GB). The requirement is to persist the xml data in to database. Currently this is achieved in 3 steps. Read the large file with less memory foot print as much as possible Create entities from the xml-data Store the data from the created entities in to the database using SqlBulkCopy. To achieve better performance I want to create a Producer-consumer model where the producer creates a set of entities say a batch of 10K and adds it to a Queue. And the

Migrating ASP.NET (MVC 2) on .NET 3.5 over to .NET 4 #gotchas

佐手、 提交于 2019-12-22 00:34:58
问题 I've currently got a ASP.NET MVC 2 application on .NET 3.5 and I want to migrate it over to the new .NET 4.0 with Visual Studio 2010. Reason being that it's always good to stay on top of these things - plus I really like the new automatic encoding with <%: %> and clean web.config :-) So, does anyone have any experience they could share? Looking for gotchas and the likes. I guess this could also apply to any ASP.NET Forms projects aswell. TIA, Charles 回答1: Gotcha #1 - Changes application pool

Sign data using smart card's private key with ASP.NET, Windows Authentication, and Impersonation

眉间皱痕 提交于 2019-12-22 00:19:52
问题 I want to know if it is possible to sign data using a smart card's private key without resorting to a java applet or activex control. I am tantalizingly close! Our environment is: AD Domain PKI infrastructure/smart cards (PIV) I knocked up a simple ASP.NET (.net 4.0) web forms app with: Windows Authentication on, Anonymous off Identity Impersonate on With the smart card in the reader I can easily enumerate the certificates on the logged-in user's smart card (StoreLocation.CurrentUser).

Sending Email via GMail and .NET 4

China☆狼群 提交于 2019-12-22 00:14:49
问题 Does .NET 4 has any problems in sending emails? I had a .NET 3.5 solution and it was working then migrated the solution to .NET 4 and It does not works; nothing changed! Notes: I get this exception: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail

HttpContext does not work in global.asax.cs

試著忘記壹切 提交于 2019-12-21 23:06:38
问题 I have this code in the global.asax.cs protected void Application_Start(object sender, EventArgs e) { string logFile = HttpContext.Current.Request.PhysicalApplicationPath + "log4net.config"; } It works fine in .NET 4.0, but throws the following exception when using in .NET 4.5. Request is not available in this context 回答1: Error seems pretty clear - the Request object is not available in that event. Try HttpRuntime.AppDomainAppPath or Server.MapPath(".") instead. 回答2: The answer is quite

Random 401 errors on an auto compiled asp.net site when updated pages are pushed

二次信任 提交于 2019-12-21 21:35:48
问题 We have an asp.net web site that is deployed on several IIS servers. The site is compile-on-demand as opposed to a pre-compiled web application. Normally deployments go fine but every now and again we get a 401 for one of the deployed pages on one of the servers. There is nothing special about which page or which server apart from the fact that it's generally the higher traffic pages that it happens to. The only way to rectify this is to deploy the same page again. The ACLs look fine on the

Watch another application and if it closes close my app (without polling) c#

天大地大妈咪最大 提交于 2019-12-21 21:17:55
问题 hi I want to "hook" another application so when it closes I can close my application. I don't want to poll the running process as this seems unnecessarily intensive, if I want to respond in real-time. I believe apps send out message within windows when they are created or closed etc how can I hook this to know when it closes? for example lets say my app loads checks running processes to ensure notepad is loaded and if so it remains loaded until notepad is closed. as notepad is closed my app