.net-4.0

MemoryCache UpdateCallback not working

Deadly 提交于 2019-12-10 14:50:11
问题 I'm trying to create a pool of connections to a third-party API, and have connections expire after an interval if they are not in use. When they expire, they need to be disconnected via the third-party API. It appeared that MemoryCache (System.Runtime.Caching) would handle this. UpdateCallback seems to behave oddly, though. A simple LINQPad example: void Main() { var cache = MemoryCache.Default; var policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(1);

Keep SelectedItem during filter of CollectionViewSource

安稳与你 提交于 2019-12-10 14:34:39
问题 I have a listbox that is being filter like this: var view = CollectionViewSource.GetDefaultView(FilterSource); view.Filter = FilterCode; I am running into a problem where the SelectedItem is getting lost when the filter is used with viewmodel code like this: VM { public ObservableCollection<Model> Items{get;set;} public Model SelectedItem { get{return _selectedItem;} set{_selectedItem = value; NotifyPropertyChanged();} } } When the filter is applied, the SelectedItem is set to null . However,

How to make Entity Framework CTP5 work with SQLite?

十年热恋 提交于 2019-12-10 14:28:34
问题 I am having a very hard time in using the SQLite db with EF CTP5. I was just trying to execute this MSDN example with SQLite. But at the line var food = db.Categories.Find("FOOD"); I am getting a runtime exception: System.Data.SQLite.SQLiteException (0x80004005): SQLite errorno such table: Categories Note: The app.config file has to be modified and is as follows: App.config <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" /> </startup>

BigInteger.Parse() on hexadecimal number gives negative numbers

為{幸葍}努か 提交于 2019-12-10 14:22:44
问题 I've started using .NET 4 System.Numerics.BigInteger Structure and I've encountered a problem. I'm trying to parse a string that contains a hexadecimal number with no sign (positive). I'm getting a negative number. For example, I do the following two asserts: Assert.IsTrue(System.Int64.Parse("8", NumberStyles.HexNumber, CultureInfo.InvariantCulture) > 0, "Int64"); Assert.IsTrue(System.Numerics.BigInteger.Parse("8", NumberStyles.HexNumber, CultureInfo.InvariantCulture) > 0, "BigInteger"); The

.NET 4.0 Implementing OutputCacheProvider

a 夏天 提交于 2019-12-10 14:19:16
问题 I am checking out the OutputCacheProvider in ASP.NET 4.0 and using it to store my output cache into the MongoDb database. I am not able to understand the purpose of Add method which is one of the override methods for OutputCacheProvider. The Add method is invoked when you have VaryByParam set to something. So, if I have VaryByParam = "id" then the Add method will be invoked. But after the Add the Set is also invoked and I can insert into the MongoDb database inside the Set method. public

Every other Visual Studio “run test” attempt results in “Unable to start program QTAgent32.exe”

情到浓时终转凉″ 提交于 2019-12-10 14:19:08
问题 Whenever I run a test, and then try to run a test again, I get the following error: Failed to queue test run. Unable to start program 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\QTAgent32.exe'. If I run the test again after that, it proceeds as normal. In other words, I get this error every other time I try to run a test. It doesn't matter whether the previous test succeeded or failed, whether it ran to completion or was interrupted, or whether I run one test or all of

Unobserved task exceptions in .NET4

…衆ロ難τιáo~ 提交于 2019-12-10 14:00:26
问题 According to some articles and blogs a code like the following one should lead to an exception in .NET 4 static void Main(string[] args) { Task.Factory.StartNew(() => { throw new Exception(); }); Thread.Sleep(1000); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("Completed"); } Expected exception: Unhandled Exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved

Send a report directly to printer with Reporting Services

╄→尐↘猪︶ㄣ 提交于 2019-12-10 14:00:04
问题 I want to print a report from a button click. I just don't need (in fact, I don't want) to view the report before printing. Just pass some parameters and send it to printer (doesn't matter if it's with or without a print dialog). 回答1: Here is a guide from MSDN for doing it with client-side reports: http://msdn.microsoft.com/en-us/library/ms252091%28v=vs.80%29.aspx and server reports: http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/25973909-592e-42fc-a454-dadda2604882 来源

Require the .NET 4.0 Full profile with <supportedRuntime />

烈酒焚心 提交于 2019-12-10 13:58:17
问题 We have an application that supports both .NET 2.0 and .NET 4.0 and we switch the few framework dependent assemblies with <bindingRedirect /> . We've used the <supportedRuntime /> element to allow the application to run using the latest framework if available. However, we do still require the full profile, not just the client profile. The documentation for .NET 3.5 indicates that you must explicitly opt-in to client only support by adding a sku="client" attribute to the <supportedRuntime />

FileSystemWatcher fails with 1000 files creations

半世苍凉 提交于 2019-12-10 13:50:05
问题 I'm using FileSystemWatcher to monitor folder A. if a file is created or copied into that folder, it will be moved to folder B. I created a file in folder A by right clicking, selecting "New", select "Text Document". The file is moved to folder B immediately. But if I use a program to create 1000 files into folder A then they are not moved to folder B. As it would seem FileSystemWatcher can't detect 1000 files were created by program. Can anyone explain this for me? 回答1: Looks like a 1000