5

Hệ thống thông tinApp không sụp đổ khi gỡ lỗi, nhưng Có Khi Chạy thường

  • Windows 10 kỹ thuật trước (xây dựng 9926)
  • Visual Studio 2013 Cộng đồng

    Cố gắng để gỡ lỗi trên:
  • [AT & T] Lumia 635 (Bản xem trước kỹ thuật cho Windows 10 cho điện thoại được xây dựng 9941 w/Lumia Cyan)
  • [AT & T] Lumia 1520 (Windows Phone 8.1 với Lumia Denim và PFD)
  • [Unlocked] BLU Win Jr (Windows Phone 8.1 với PFD)
  • [Verizon] Lumia Icon (Windows Phone 8.1 với Lumia Denim và PFD)

tôi cố gắng để có được dịch vụ định vị làm việc trong ứng dụng của tôi. Trước đây, tôi đã có Visual Studio ném lỗi. Đó là một số ArgumentException với thông báo "Use of undefined keyword value 1 for event TaskScheduled in async". Googling không bật lên bất kỳ giải pháp nào.

Đây là mã:

Geolocator Locator = new Geolocator(); 
Geoposition Position = await Locator.GetGeopositionAsync(); 
Geocoordinate Coordinate = Position.Coordinate; 

Khi tôi có thể nhận được lỗi được ném ra, các ngoại lệ được ném trên dòng thứ 2 hoặc thứ 3 trong ví dụ trên. tôi đơn giản hóa mã gốc để thử và sửa chữa nó, nhưng đây là bản gốc:

Geolocator Locator = new Geolocator(); 
Geocoordinate Coordinate = (await Locator.GetGeopositionAsync()).Position.Coordinate; 

Toàn bộ ứng dụng hoạt động khi gỡ lỗi, nhưng bị treo gần như ngay lập tức bằng cách khác.

Đây là dự án Windows 8.1 Universal, tập trung vào dự án điện thoại.

Cảm ơn trước


EDIT: Theo yêu cầu, ở đây có đầy đủ các phương pháp:

private static bool CheckConnection() 
{ 
    ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile(); 
    bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess; 
    return internet; 
} 
public static async Task<double> GetTemperature(bool Force) 
{ 
    if (CheckConnection() || Force) 
    { 
     Geolocator Locator = new Geolocator(); 
     await Task.Yield(); //Error occurs here 
     Geoposition Position = await Locator.GetGeopositionAsync(); 
     Geocoordinate Coordinate = Position.Coordinate; 
     HttpClient Client = new HttpClient(); 
     double Temperature; 
     Uri u = new Uri(string.Format("http://api.worldweatheronline.com/free/v1/weather.ashx?q={0},{1}&format=xml&num_of_days=1&date=today&cc=yes&key={2}", 
             Coordinate.Point.Position.Latitude, 
             Coordinate.Point.Position.Longitude, 
             "API KEY"), 
             UriKind.Absolute); 
     string Raw = await Client.GetStringAsync(u); 
     XElement main = XElement.Parse(Raw), current_condition, temp_c; 
     current_condition = main.Element("current_condition"); 
     temp_c = current_condition.Element("temp_C"); 
     Temperature = Convert.ToDouble(temp_c.Value); 
     switch (Memory.TempUnit) 
     { 
      case 0: 
       Temperature = Convertions.Temperature.CelsiusToFahrenheit(Temperature); 
       break; 
      case 2: 
       Temperature = Convertions.Temperature.CelsiusToKelvin(Temperature); 
       break; 
     } 
     return Temperature; 
    } 
    else 
    { 
     throw new InvalidOperationException("Cannot connect to the weather server."); 
    } 
} 

EDIT 2: Tôi đã asked for help on Twitter, và received a reply hỏi cho một dự án repro. Tôi đã tạo lại phần chính của ứng dụng gốc, nhưng tôi không thể nhận được lỗi. Tuy nhiên, lỗi có thể xảy ra cho bạn so here's the project.


EDIT 3: Nếu nó giúp ở tất cả, đây là các chi tiết ngoại lệ:

System.ArgumentException occurred 
    _HResult=-2147024809 
    _message=Use of undefined keyword value 1 for event TaskScheduled. 
    HResult=-2147024809 
    IsTransient=false 
    Message=Use of undefined keyword value 1 for event TaskScheduled. 
    Source=mscorlib 
    StackTrace: 
     at System.Diagnostics.Tracing.ManifestBuilder.GetKeywords(UInt64 keywords, String eventName) 
    InnerException: 
+0

Bạn không đơn độc, hãy kiểm tra [this] (https://social.msdn.microsoft. com/Diễn đàn/windowsapps/en-US/3e505e04-7f30-4313-aa47-275eaef333dd/systemargumentexception-use-of-undefined-keyword-value-1-for-event-taskcheduled-in-async? forum = wpdevelop) và [ này] (http://stackoverflow.com/questions/24747885/argumentexception-use-of-undefined-keyword-value-1-for-event-taskscheduled-in). Để giải quyết vấn đề này, hãy xem liệu điều này có giúp ích không: 'Vị trí địa lý = chờ đợi Task.Run (() => Locator.GetGeopositionAsync());' – Noseratio

+0

@Noseratio Tôi đã thử mọi thứ tôi có thể trong hai chủ đề bạn đã liên kết. Ngoài ra, tôi đã thử cách giải quyết mà bạn đã đưa ra. Nó vẫn hoạt động hoàn hảo trong khi gỡ lỗi, nhưng nó vẫn treo trong khi không gỡ lỗi. Cảm ơn bạn đã trả lời –

+0

Rõ ràng, đó là lỗi WP/WRT, tôi báo cáo tại http://connect.microsoft.com. BTW, hãy thử điều này: 'chờ đợi Task.Yeild(); Geocoordinate Coordinate = (đang chờ Locator.GetGeopositionAsync()) Position.Coordinate; 'Nó có bị sập sau' Task.Yeild() 'hay sau khi' đang chờ Locator.GetGeopositionAsync() '? – Noseratio

Trả lời

1

Sau khi kiểm tra thisthis, tôi tin rằng đây là một lỗi trong .NET async/await infrastructure for WinRT.Tôi không thể repro nó, nhưng tôi khuyến khích bạn thử workaround sau đây, xem nếu nó làm việc cho bạn.

  • Yếu tố ra tất cả các cuộc gọi awaitable không đồng bộ từ OnNavigatedTo thành một phương pháp riêng biệt async Task, ví dụ ContinueAsync:

    async Task ContinueAsync() 
    { 
        Geolocator Locator = new Geolocator(); 
        Geoposition Position = await Locator.GetGeopositionAsync(); 
        Geocoordinate Coordinate = Position.Coordinate; 
    
        // ... 
    
        var messageDialog = new Windows.UI.Popups.MessageDialog("Hello"); 
        await messageDialog.ShowAsync(); 
    
        // ... 
    } 
    
  • Di async modifier từ OnNavigatedTo và gọi ContinueAsync từ OnNavigatedTo như thế này:

    var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); 
    Task.Factory.StartNew(
        () => ContinueAsync(), 
        CancellationToken.None, TaskCreationOptions.None, scheduler). 
        Unwrap(). 
        ContinueWith(t => 
        { 
         try 
         { 
          t.GetAwaiter().GetResult(); 
         } 
         catch (Exception ex) 
         { 
          Debug.WriteLine(ex); 
          throw; // re-throw or handle somehow 
         } 
        }, 
        CancellationToken.None,    
        TaskContinuationOptions.NotOnRanToCompletion, 
        scheduler); 
    

Cho chúng tôi biết nếu nó giúp :)


Đã cập nhật, rõ ràng là lỗi ở đâu đó trong nhà cung cấp đăng nhập TPL, TplEtwProvider. Bạn có thể thấy nó đang được tạo nếu bạn thêm mã bên dưới. Cho đến nay, tôi không thể tìm cách tắt nguồn sự kiện này (trực tiếp hoặc qua Phản ánh):

internal class MyEventListener : EventListener 
{ 
    protected override void OnEventSourceCreated(EventSource eventSource) 
    { 
     base.OnEventSourceCreated(eventSource); 
     if (eventSource.Name == "System.Threading.Tasks.TplEventSource") 
     { 
      var enabled = eventSource.IsEnabled(); 

      // trying to disable - unsupported command :(
      System.Diagnostics.Tracing.EventSource.SendCommand(
       eventSource, EventCommand.Disable, new System.Collections.Generic.Dictionary<string, string>()); 
     } 
    } 
} 

// ... 
public sealed partial class App : Application 
{ 
    static MyEventListener listener = new MyEventListener(); 
} 
+0

Cảm ơn sự giúp đỡ của bạn, nhưng tôi vẫn không thể làm việc này. Tôi không biết tại sao điều này lại xảy ra và tôi thấy rằng nhiều người khác cũng đang nhận được điều này. –

+0

Xin chào Greg - Tôi nghĩ đây là lỗi. Tôi sẽ gửi và cập nhật cho bạn khi tôi biết thêm. Tôi không thể hứa sẽ sửa chữa nhanh như thế nào. Vui lòng đăng liên kết đến dự án sinh sản trên OneDrive và tôi sẽ có thứ gì đó để chuyển tiếp tới PG. –

+0

@MattSmall, hãy xem cập nhật của tôi về nguồn sự kiện 'TplEtwProvider'.Có thể tắt hoàn toàn ứng dụng cho Windows Phone/Windows Store không? – Noseratio

Các vấn đề liên quan