.net-4.0

Produce a .NET 4.0 library from a PCL Project where code is identical

人走茶凉 提交于 2019-12-12 08:58:59
问题 It's quite frustrating, I have a Portable Class Library (PCL) library that had to drop .NET 4.0 in the profile to have access to the right API's "in PCL land". However, these API's do exist in .NET 4.0, such that if the exact same code is in a .NET 4.0 project it compiles just fine. I want a minimal ongoing maintenance way to recompile the code in this PCL project to .net 4.0 so I can include it in a Nuget package. 回答1: With minimal conditional adjustments to the .csproj , an msbuild project

c# lock and listen to CancellationToken

一个人想着一个人 提交于 2019-12-12 08:33:28
问题 I want to use lock or a similar synchronization to protect a critical section. At the same time I want to listen to a CancellationToken. Right now I'm using a mutex like this, but mutex doesn't have as good performance. Can I use any of other synchronization classes (including the new .Net 4.0) instead of the mutex? WaitHandle.WaitAny(new[] { CancelToken.WaitHandle, _mutex}); CancelToken.ThrowIfCancellationRequested(); 回答1: Take a look at the new .NET 4.0 Framework feature SemaphoreSlim Class

Is it possible create a scalable WCF service with thousands of long-running TCP connections?

早过忘川 提交于 2019-12-12 08:13:34
问题 I'm attempting to create a WCF service where several thousand (~10,000) clients can connect via a duplex NetTcpBinding for extended periods of time (weeks, maybe months). After a bit of reading, it looks like it's better to host in IIS than a custom application or Windows service. Is using WCF for such a service acceptable, or even possible? If so, where can I expect to run into throttling or performance issues, such as increasing the WCF ListenBacklog & MaxConcurrentConnections? Thanks! 回答1:

Authentication and Roles in WPF

纵然是瞬间 提交于 2019-12-12 08:03:29
问题 I am doing a project in WPF. I got a requirement to authenticate a user and providing accessibilty for the modules based on the role. Do i have a better way to achieve this in WPF. 回答1: It will depend in part on how secure you need the code to be. For all your use cases, though, use a Model-View-ViewModel pattern. In each ViewModel, perhaps best placed in a base class for all your ViewModel classes, include a state variable which returns a string and raises the PropertyChanged event whenever

Quick way to get the contents of a MemoryStream as an ASCII string

試著忘記壹切 提交于 2019-12-12 07:47:18
问题 I have a JSON string in a MemoryStream. I am using the following code to get it out as an ASCII string: MemoryStream memstream = new MemoryStream(); /* Write a JSON string to memstream here */ byte[] jsonBytes = new byte[memstream.Length]; memstream.Read(jsonBytes, 0, (int)memstream.Length); string jsonString = Encoding.ASCII.GetString(jsonBytes); What is a shorter/shortest way to do this? 回答1: You could use the ToArray method: using (var stream = new MemoryStream()) { /* Write a JSON string

SerialData.Eof circumstances

╄→尐↘猪︶ㄣ 提交于 2019-12-12 07:14:44
问题 In my SerialPort.DataReceived event handler, I am checking for SerialData.Eof: void DataReceived(object sender, SerialDataReceivedEventArgs e) { if (e.EventType == SerialData.Eof) throw new NotImplementedException("SerialData.Eof"); // ... Read } In my entire development up to this point, I have never hit this exception. But today, when working on a different piece of the protocol, it hit. My question is, what exactly does SerialData.Eof mean? MSDN says: The end of file character was received

Build error “Are you missing a using directive or assembly reference” - target framework version 4

浪尽此生 提交于 2019-12-12 06:49:49
问题 I've got a project that uses a library (from nuget) The target framework for my project is currently 4.0 I'm using objects and methods from the library, I get intellisense etc... However, when I build, compilation fails with The type or namespace could not be found. Are you missing a using directive or assembly reference? If I change the target framework of the project to 4.5, it compiles. Is there a way round this? EDIT As a specific example, here are the steps to reproduce this problem in

WPF Jitters with TranslateTransform and Canvas.SetLeft

别来无恙 提交于 2019-12-12 06:24:24
问题 I'm running into a problem of "jitters" when moving the X, Y coordinates of controls. Basically, I got an animation to work two different ways: 1) TranslateTransform of the X property, and 2) A Timer that calls Canvas.SetLeft. Both of which cause the image to move, but not smoothly. XAML: <Canvas Margin="0" Name="CanvasContainer"> <Canvas Margin="0" Name="FirstCanvas" Background="White"> <Image Name="FirstImage" Opacity="1" Margin="0,0,0,0" Canvas.Left="0" Canvas.Top="0" Source="someImage.png

call child control on parent page for an update of an updatepanel

半世苍凉 提交于 2019-12-12 05:31:22
问题 I am using a RadTabStrip for 2 tabs. I would like OnTabClick for the tab to do an update of the updatepanel on the page. The problem I am having is its not finding the control on the child page. My logic for the parent page protected void tabClick(object sender, RadTabStripEventArgs e) { if (e.Tab.SelectedIndex == 0) { UpdatePanel tab1 = (UpdatePanel)Page.FindControl("up_EntirePage_Tab1"); tab1.Update(); } else { UpdatePanel tab2 = (UpdatePanel)Page.FindControl("up_EntirePage_Tab2"); tab2

AjaxFileUpload control doesnt work when page have querystring in asp.net

混江龙づ霸主 提交于 2019-12-12 04:48:58
问题 I have a button on a .aspx page which opens the popup to upload images of selected item. ListEdit.aspx <asp:Button ID="btnListingImageUpload" runat="server" Text="Upload Images" OnClientClick="basicPopup()"/> Javascript: function basicPopup() { var QuoteId = document.getElementById('<%= hdnQuoteIDForListing.ClientID%>').value; var IsPrep = document.getElementById('<%= hdnIsPrep.ClientID%>').value; alert(IsPrep); popupWindow = window.showModalDialog('ListingImageUpload.aspx?QuoteID=' + QuoteId