c#-5.0

Unhandled exception handler not called for Metro / WinRT UI async void event handler

主宰稳场 提交于 2019-12-28 13:22:15
问题 Consider the following to be extracts from a Windows 8 Metro / WinRT app, which have been reduced to the bare minimum required to show the anomaly: public class App : Application { public App() { UnhandledException += (sender, e) => e.Handled = true; } } public class MainPage : Page { private void Button_Click_1(object sender, RoutedEventArgs e) { throw new NotSupportedException(); } private async void Button_Click_2(object sender, RoutedEventArgs e) { throw new NotSupportedException(); } }

Await async clarification

拟墨画扇 提交于 2019-12-24 12:21:23
问题 I am trying to learn/understand more about async/await in C# and I would put myself in rookie category so all your comments/suggestions are welcome. I wrote small test to have better understanding and clarification about await/async. My program freezes after "GetStringLength" call I tried reading several things but looks like I am stuck and I thought of taking expert opinion on what I might be doing wrong. Can you please guide me or point me in right direction here? using System; using System

No verification code while registering number via message using twilio trial

岁酱吖の 提交于 2019-12-24 11:18:00
问题 Hi I am on trial with twilio. I have seen this link: https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work It says "You must verify a phone number before you can send SMS messages to it from your trial phone number." And also restricts on the outgoing text But what if I just want to verfiy the number, using: var twilio = new TwilioRestClient( Keys.TwilioSid, Keys.TwilioToken ); var result = twilio.SendMessage( Keys.FromPhone, message.Destination, message.Body); //

Exception not caught in Task.Run wrapped method

痴心易碎 提交于 2019-12-24 10:48:06
问题 New to async await integration in C# 5. I'm working with some basic Task based methods to explore async await and the TPL. In this example below I'm calling a web service with a timeout of 5 seconds. If the timeout expires it should throw an exception so I can return false from the method. However, the timeout never occurs, or maybe it does but the Task never returns. public static Task<bool> IsConnectedAsync() { return Task.Run(() => { try { using (WSAppService.AppService svc = new

How to test _set.Contains(obj), when _set is HashSet<T1>, obj isT2, and T1, T2 both implement same interface?

不问归期 提交于 2019-12-24 08:49:24
问题 I must implement an ObservableHashSet<T> that can quickly ( O(1) ) test for object existence: public class ObservableHashSet<T> : ObservableCollection<T>{ readonly ISet<T> _set = new HashSet<T>(); protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e){ base.OnCollectionChanged(e); if (e.Action == NotifyCollectionChangedAction.Move) return; if (e.OldItems != null) foreach (var old in e.OldItems.Cast<T>()) _set.Remove(old.GetHashable()); if (e.NewItems == null) return;

Iterators in VB.NET vNext, and limitations of iterators in C#

倖福魔咒の 提交于 2019-12-23 12:01:29
问题 I just saw on the Async CTP website that the next version of VB.NET will have iterators. I guess they included iterators because the rewriting process is similar to the one used for the new async / await feature. But reading the document that explains the feature, I realized that VB.NET iterators will actually have features that are not available in C# today, namely: iterator blocks in a try/catch block anonymous iterator blocks These were known limitations in C#. Is there any chance that

XmlWriter async methods

牧云@^-^@ 提交于 2019-12-23 07:16:40
问题 I have found example of async using of XmlWriter within msdn documentation http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx async Task TestWriter(Stream stream) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Async = true; using (XmlWriter writer = XmlWriter.Create(stream, settings)) { await writer.WriteStartElementAsync("pf", "root", "http://ns"); await writer.WriteStartElementAsync(null, "sub", null); await writer.WriteAttributeStringAsync(null, "att", null

async await execution windows phone 8

半城伤御伤魂 提交于 2019-12-23 02:28:35
问题 I am new to async and await style of programming. How can I solve the following problem: I am calling the below code first. The problem here is that the first line is awaiting which need to populate the categoriesvm.Categorieslist , which it does not, but the second line is called. (which I think is the default behaviour of await) How can I make sure that the second line is called only when the categoriesvm.Categorieslist is populated in the first line? protected override void OnNavigatedTo

RESTful authentication. Client-side, stateless unauthentication

夙愿已清 提交于 2019-12-21 15:07:14
问题 I'm implementing a set of RESTful services for some developments and one of these is an authentication service . This authentication service authenticates two kinds of identities: Applications . AppKey-based authentication so clients must register for a key in order to access to the rest of the services . Users . Well-known credentials (user+password)-based user authentication so humans and machines can work with these RESTful services through client applications. These RESTful services are

Why compiler does not allow using await inside catch block

泄露秘密 提交于 2019-12-21 07:12:18
问题 Let say I have an async method: public async Task Do() { await Task.Delay(1000); } Another method is trying to call Do method inside catch block public async Task DoMore() { try { } catch (Exception) { await Do(); //compiled error. } } But this way, the compiler does not allow using await inside catch , is there any reason behind the scene why we could not use it that way? 回答1: Update This will be supported in C# 6. It turned out that it wasn't fundamentally impossible, and the team worked