0

Temelde, ne oluyor, o çöküyor. Ayrıca, uygulama ad alanıyla oluşturulmuş bir değişkeni değiştirmeyi denediğimde yalnızca çöküyor gibi görünüyor. Başka bir deyişle, yeni bir namus ve yönetilen sınıf oluşturursam, değişkenleri çok iyi değiştirebilirim. Buyönetilen C++ sınıfları kazasında

UberSnipAPI->Http->RequestURL = "http://api.ubersnip.com/categories.php"; 

çökmez

crash

void ASynTaskCategories(void) 
    { 
     concurrency::task_completion_event<Platform::String^> taskDone; 
     MainPage^ rootPage = this; 
     UberSnip::HELPER::ASYNC_RESPONSE^ responseItem = ref new UberSnip::HELPER::ASYNC_RESPONSE(); 
     create_task([taskDone, responseItem, rootPage]() -> Platform::String^ 
     { 

      //UBERSNIP API 0.4 
      UberSnip::UBERSNIP_CLIENT* UberSnipAPI = new UberSnip::UBERSNIP_CLIENT(); 

      UberSnipAPI->Http->RequestURL = "http://api.ubersnip.com/categories.php"; 
      UberSnipAPI->Http->request(); 
      taskDone.set(UberSnipAPI->Client->BodyResponse); 
      responseItem->Body = UberSnipAPI->Client->BodyResponse; 
      return "(done)"; 

     }).then([taskDone, responseItem, rootPage](Platform::String^ BodyResponse) { 
      Platform::String^ BR = responseItem->Body; 


      cJSON* cats = cJSON_Parse(_string(BR)); 
      cats = cats->child; 
      int *cat_count = new int(cJSON_GetArraySize(cats)); 
      rootPage->Categories->Clear(); 

      GENERIC_ITEM^ all_item = ref new GENERIC_ITEM(); 
      all_item->Title = "All"; 

      rootPage->Categories->Append(all_item); 
      for (int i = 0; i < *cat_count; i++) { 
       cJSON* cat = new cJSON(); 
       cat = cJSON_GetArrayItem(cats, i); 

       string *track_title = new string(cJSON_GetObjectItem(cat, "name")->valuestring); 

       GENERIC_ITEM gitem; 
       gitem.Title = "Hi"; 

       GENERIC_ITEM^ ubersnipCategory = ref new GENERIC_ITEM(); 
       ubersnipCategory->Title = _String(*track_title); 

       rootPage->Categories->Append(ubersnipCategory); 
      } 
     }); 

ama bu bir

all_item->Title = "All"; 

buna uygulamalar varsayılan olmak ile bir ilgisi vardır neredeyse olumlu diliyorum ad alanı ve ana iş parçacığı dışında erişiliyor ... En azından bu ne? Ems gerçekten gerçek sınıf dışında tek fark bu gibi.

Bu GENERIC_ITEM böyle görünüyor.

[Windows::UI::Xaml::Data::Bindable] 
public ref class GENERIC_ITEM sealed { 
private: 
    Platform::String^ _title = ""; 
    Platform::String^ _description; 
    Windows::UI::Xaml::Media::ImageSource^ _Image; 

    event PropertyChangedEventHandler^ _PropertyChanged; 

    void OnPropertyChanged(Platform::String^ propertyName) 
    { 
     PropertyChangedEventArgs^ pcea = ref new PropertyChangedEventArgs(propertyName); 
     _PropertyChanged(this, pcea); 
    } 
public: 
    GENERIC_ITEM() { 

    }; 

    property Platform::String^ Title { 
     Platform::String^ get() { 
      return this->_title; 
     } 

     void set(Platform::String^ val) { 
      this->_title = val; 
      OnPropertyChanged("Title"); 
     } 
    } 

    property Platform::String^ Description { 
     Platform::String^ get() { 
      return this->_description; 
     } 

     void set(Platform::String^ val) { 
      this->_description = val; 
      OnPropertyChanged("Description"); 
     } 
    } 

    void SetImage(Platform::String^ path) 
    { 
     Windows::Foundation::Uri^ uri = ref new Windows::Foundation::Uri(path); 
     _Image = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(uri); 
    } 

}; 

ben ilk parçacığı üzerinde bu kodun aynısını çalıştırırsanız mükemmel çalışıyor çünkü sınıf ile hiçbir sorun olduğunu biliyorum.

Herhangi bir öneriniz var mı? Teşekkürler! : D

cevap

0

Birkaç saat geçmesine rağmen çözdü! Başka vaka birisi bu sorunu yaşayan tek yapmanız gereken tüm UI iş parçacığı dışında kullanılamaz geldiğinde UI üzerinde kod çalıştırmasına Dispatcher kullanmaktır.

void loadCats(UberSnip::HELPER::ASYNC_RESPONSE^ responseItem, MainPage^ rootPage) { 
    Platform::String^ BR = responseItem->Body; 


    cJSON* cats = cJSON_Parse(_string(BR)); 
    cats = cats->child; 
    int *cat_count = new int(cJSON_GetArraySize(cats)); 
    rootPage->Categories->Clear(); 

    GENERIC_ITEM^ all_item = ref new GENERIC_ITEM(); 
    all_item->Title = "All"; 

    rootPage->Categories->Append(all_item); 
    for (int i = 0; i < *cat_count; i++) { 
     cJSON* cat = new cJSON(); 
     cat = cJSON_GetArrayItem(cats, i); 

     string *track_title = new string(cJSON_GetObjectItem(cat, "name")->valuestring); 

     GENERIC_ITEM gitem; 
     gitem.Title = "Hi"; 

     GENERIC_ITEM^ ubersnipCategory = ref new GENERIC_ITEM(); 
     ubersnipCategory->Title = _String(*track_title); 

     rootPage->Categories->Append(ubersnipCategory); 
    } 
} 

void ASyncTaskCategories(void) 
{ 
    concurrency::task_completion_event<Platform::String^> taskDone; 
    MainPage^ rootPage = this; 
    UberSnip::HELPER::ASYNC_RESPONSE^ responseItem = ref new UberSnip::HELPER::ASYNC_RESPONSE(); 

    auto dispatch = CoreWindow::GetForCurrentThread()->Dispatcher; 
    auto op2 = create_async([taskDone, responseItem, rootPage, dispatch] { 
     return create_task([taskDone, responseItem, rootPage, dispatch]() -> Platform::String^ 
     { 

      //UBERSNIP API 0.4 
      UberSnip::UBERSNIP_CLIENT* UberSnipAPI = new UberSnip::UBERSNIP_CLIENT(); 

      UberSnipAPI->Http->RequestURL = "http://api.ubersnip.com/categories.php"; 

      try{ 
       UberSnipAPI->Http->request(); 
      } 
      catch (...) { 
       printf("Error"); 
      } 

      int err = UberSnip::UTILS::STRING::StringToAscIIChars(UberSnipAPI->Client->BodyResponse).find("__api_err"); 

      if (err < 0) { 
       if (UberSnip::UTILS::STRING::StringToAscIIChars(UberSnipAPI->Client->BodyResponse).length() < 3) { 
        return; 
       } 
      } 
      taskDone.set(UberSnipAPI->Client->BodyResponse); 
      responseItem->Body = UberSnipAPI->Client->BodyResponse; 
      dispatch->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]() 
      { 
       rootPage->loadCats(responseItem, rootPage); 
      })); 

      for (int i = 0; i < 100;) { 

      } 


      return "(done)"; 

     }).then([taskDone, responseItem, rootPage](Platform::String^ BodyResponse) { 
     }); 

    }); 

     //rootPage->loadCats(responseItem, rootPage); 
} 
İlgili konular