.net-4.0

Timer callback closes WPF app (DispatcherTimer works..)

南笙酒味 提交于 2019-12-10 16:46:39
问题 I have a WPF app with a textblock that displays the current time. Said textblock is bound to a DependencyProperty on the ViewModel. Naturally I need to keep updating the time, so I used a timer (System.Threading.Timer) like so: public MainViewModel() { _dateTimer = new Timer(_dateTimer_Tick, null, 0, 60000); } void _dateTimer_Tick(object sender) { Time = DateTime.Now.ToString("HH:mm"); Date = DateTime.Now.ToString("D"); } The thing is, when the callback is called, the app exits... bummer

calling .net 4 from .net 3.5 via self hosted wcf service

假装没事ソ 提交于 2019-12-10 16:33:57
问题 I have a .net 3.5 application. It cannot be migrated to 4. I need to call a .net 4 assembly from my application. I thought to create a new executable in .net 4 which has a self hosted wcf service that is an adapter over the 4 assembly. My 3.5 app can then execute the external process and call the assembly. This is a little ugly - any better idea? 回答1: Google says it is possible. It seems there is a new feature in .Net 4 called Inproc Sxs (In process side by side). Have a look here : http:/

Is static method thread safe

南笙酒味 提交于 2019-12-10 16:15:27
问题 If I have a static method to convert one object to another object, is this method thread safe in C#? public static AnotherDataClass Convert(MyDataClass target) { AnotherDataClass val = new AnotherDataClass(); // read infomration from target // put information into val; return val; } Just want to make the question more clear.... when invoke the convert method.... we can assume that target is not going be be modified. since the Convert method only interested in the "attrubite" of target 回答1: No

How to make PLINQ to spawn more concurrent threads in .NET 4.0 beta 2?

纵然是瞬间 提交于 2019-12-10 16:02:55
问题 In former versions of Parallel Extensions you could set the number of threads: enumerable.AsParallel(numberOfThreads) But now that overload is not available anymore. How to do it now? 回答1: In the new version you can specify it with the extension method ".WithDegreeOfParallelism(int degreeOfParallelism)". IE: enumerable.AsParallel().WithDegreeOfParallelism(numberOfThreads) 回答2: I really have no idea why it changed, so I can't answer the question, but it seems like if the developer specifies

Are Linq's Skip and Take optimized for arrays? [4.0 edition]

时光怂恿深爱的人放手 提交于 2019-12-10 15:59:45
问题 It's a common situation to copy a range from an array. C# supports this operation in various ways, for instance using Array.Copy, but also by Linq's Skip and Take combination. Starting at .NET 4.0, do the Skip and Take operations still add considerable overhead, or do they recognize (either at compile time or at run time) their target is an array? To clarify: I am referring to a) the time taken to skip the initial bytes and b) to the combination of Skip-Take-ToArray, which does not suffer

The requested operation is not supported in CngKey.Create

青春壹個敷衍的年華 提交于 2019-12-10 15:59:05
问题 I'm trying to generate a self-signed certificate on the fly (programmatically) in a C# assembly (targeting .NET 4.0 ), to serve as a root CA to generate other certificates. The certificate doesn't need to be persisted in the Windows certificate store, I'll export it as a file. Reading through this question (and in particular, @dthorpe's answer), I decided to give a try to CLR Security. The CLR Security library put an extension method on CngKey class to generate a self-signed certificate, but

Application.LoadComponent fails when loading from an unreferenced assembly

不羁的心 提交于 2019-12-10 15:44:06
问题 I have a WPF application that needs to be able to load predefined UserControl s based upon a Uri. I'm using Application.LoadComponent(Uri) to do this, but it's now throwing an IOException with Cannot locate resource... . My original architecture looked like this and worked as expected: Application Assembly/ Main Window.xaml Custom Control.xaml Dynamically Loaded Control.xaml Second Assembly/ Class that executes Application.LoadComponent("Dynamically Loaded Control.xaml") However, I need to be

Linking to a .Net v2.0 assembly from a .Net v4.0 assembly also appears to link (and alias) mscorlib v2.0. Why?

荒凉一梦 提交于 2019-12-10 15:43:19
问题 I have a .Net assembly which imports an assembly linked against the v2.0 runtime. The problem I'm having is that when I try to run some tests on my assembly, Fusion trys to load the wrong version of a dependent assembly. After looking at the assembly manifest, I can see why: the wrong version of FSharp.Core is linked. In my build file, I make FSharp.Core, Version=4.0.0.0 explicit, but FSharpPowerPack appears to link to v2.0.0.0, and some how seems to "win" this linking battle. Here's the

How to delete selected Items from a ListView by pressing the delete button?

风流意气都作罢 提交于 2019-12-10 15:12:26
问题 I want to delete one or more selected Items from a ListView. What is the best way to do that? I´m using C# and the dotnet Framework 4. 回答1: You can delete all selected items by iterating the ListView.SelectedItems collection and calling ListView.Remove for each item whenever the user pressed the delete key. private void listView1_KeyDown(object sender, KeyEventArgs e) { if (Keys.Delete == e.KeyCode) { foreach (ListViewItem listViewItem in ((ListView)sender).SelectedItems) { listViewItem

Does setting Security Mode = Transport automatically make it secure in a HTTPS web service?

╄→гoц情女王★ 提交于 2019-12-10 15:05:25
问题 I have a web service and we're currently hosting it in a HTTPS site. My binding is this. <wsHttpBinding> <binding maxReceivedMessageSize="2000000" > <readerQuotas maxStringContentLength="2147483647" /> <security mode="Transport"> </security> </binding> </wsHttpBinding> And it seems to work well. But my main aim is to make sure the web service requests and responses are encrypted. I don't know much about web services but is that all there is to it? Just use HTTPS and put this line in your