.net-4.5

How to - Multiple Async tasks with timeout and cancellation

老子叫甜甜 提交于 2019-12-10 20:14:53
问题 I would like to fire several tasks while setting a timeout on them. The idea is to gather the results from the tasks that beat the clock, and cancel (or even just ignore) the other tasks. I tried using extension methods WithCancellation as explained here, however throwing an exception caused WhenAll to return and supply no results. Here's what I tried, but I'm opened to other directions as well (note however that I need to use await rather than Task.Run since I need the httpContext in the

Static HttpClient still creating TIME_WAIT tcp ports

二次信任 提交于 2019-12-10 20:12:59
问题 I am experiencing some interesting behavior with the HttpClient from the .NET Framework (4.5.1+, 4.6.1 and 4.7.2). I have proposed some changes in a project at work to not dispose of the HttpClient on each use because of the known issue with high TCP port usage, see https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/. I have investigated the changes to check that things were working as expected and found that we are still experiencing the same TIME_WAIT ports as before. To confirm

How to change ILoggerFacade implementation to trace caller method using CallerMemberName attribute?

时光毁灭记忆、已成空白 提交于 2019-12-10 19:51:22
问题 I'm trying to implement logging functionality into my new WPF 4.5 CompositeWPF (Prism) project. This requires me to implement ILoggerFacade in my code. The interface only implements 1 method: Log(string message, Category category, Priority priority) . The ILoggerFacade interface: public interface ILoggerFacade { void Log(string message, Category category, Priority priority); } My implementation : public class Log4NetLogger : ILoggerFacade { private static readonly ILog m_Logger = LogManager

Correct Way to Throw and Catch Exceptions using async/await

我怕爱的太早我们不能终老 提交于 2019-12-10 19:46:09
问题 All, please take the following code: Task<bool> generateStageAsyncTask = null; generateStageAsyncTask = Task.Factory.StartNew<bool>(() => { return GenerateStage(ref workbook); }, this.token, TaskCreationOptions.LongRunning, TaskScheduler.Default); // Run core asynchroniously. bool bGenerationSuccess = false; try { bGenerationSuccess = await generateStageAsyncTask; } catch (OperationCancelledException e) { // Script cancellation. result.RunSucceeded = true; result.ResultInfo = "Script

.net core app target .net framework 4.5.2 on Linux

可紊 提交于 2019-12-10 19:27:15
问题 I wanted to understand the dot net core support a bit more. My basic understanding was that if I wanted to run a .net app on Linux then it needs to be built .net core and targeted netcoreapp1.0 framework to guarantee this. 1) I assume the above assumption is correct? 2) When I was reading various articles online, such as this one about referencing exiting .net framework project within a .net core application (https://www.hanselman.com/blog

Ajax.BeginForm to specify “GET” type posting

这一生的挚爱 提交于 2019-12-10 19:20:12
问题 My view is as below: <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> @using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "Get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "DisplayPatients" })) { <input type="search" name="searchTerm"

Iterating through JSON using System.Json

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 19:03:34
问题 I'm exploring the capabilities of .NET 4.5 System.Json library but there isn't much documentation, and it's quite tricky to search for due to the popular JSON.NET library. I am wondering basically, how I'd loop through some JSON for example: { "People": { "Simon" : { Age: 25 }, "Steve" : { Age: 15 } } } I have my JSON in a string, and I want to iterate through and display the ages of everyone. So first I'd do: var jsonObject = JsonObject.Parse(myString); but then I'm at a loss of what to do

Measure CPU cycles of a Function Call

北慕城南 提交于 2019-12-10 16:26:32
问题 I'm looking for a way to measure the cpu cycles a function call on a thread takes. Example pseudo code: void HostFunction() { var startTick = CurrentThread.CurrentTick; //does not exist ChildFunction(); var endTick = CurrentThread.CurrentTick; //does not exist var childFunctionCost = endTick - startTick; } void ChildFunction() { //Do whatever... Thread.Sleep(3000); //Do some more... } I don't want to use a Stopwatch or some other time measurement, because it would include any time that the

useLegacyV2RuntimeActivationPolicy=“true” does not work with .NET 4.5

可紊 提交于 2019-12-10 15:41:31
问题 The Top answers here: What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config? and What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project? did not help. My particular Use-case is .Net 4.5 and above for WinForms and Console apps in VS2015 , while trying to use a .net 2.0 dll Under VS2015, adding the suggested variants of this to projects config file does not help. <configuration> <startup useLegacyV2RuntimeActivationPolicy=

Cannot write settings on app.config (or no changes are shown)

半腔热情 提交于 2019-12-10 15:17:43
问题 I'm creating an application on .net framework 4.5 whenever i want to load the app config values (appSettings section) and write the changes, i don't see my changes if i refresh the section. What i am doing wrong? and how can i solve it? code private void LoadConfig() { NameValueCollection appSettings = ConfigurationManager.AppSettings; for (int i = 0; i < appSettings.Count; i++) { switch (appSettings.GetKey(i)) { case "initialCatalog": txtInitialCatalog.Text = appSettings.GetValues(i)[0];