Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 在独立存储上工作时,Schedule Agent上的交叉异常无效_C# 4.0_Windows Phone 7.1_Isolatedstorage - Fatal编程技术网

C# 4.0 在独立存储上工作时,Schedule Agent上的交叉异常无效

C# 4.0 在独立存储上工作时,Schedule Agent上的交叉异常无效,c#-4.0,windows-phone-7.1,isolatedstorage,C# 4.0,Windows Phone 7.1,Isolatedstorage,我正在使用Windows Phone Schedule Agent,并尝试在同步后更新图片名称。问题是,当我在此函数的“BitmapImage bmp=new BitmapImage();”行上遇到无效的交叉异常,我真的不明白为什么 void UpdateSyncPictureName(int AsyncStatus, int AticketID, int AsyncID, int ApictureID, int TsyncStatus = 0, int TsyncID = 0) {

我正在使用Windows Phone Schedule Agent,并尝试在同步后更新图片名称。问题是,当我在此函数的“BitmapImage bmp=new BitmapImage();”行上遇到无效的交叉异常,我真的不明白为什么

void UpdateSyncPictureName(int AsyncStatus, int AticketID, int AsyncID, int ApictureID, int TsyncStatus = 0, int TsyncID = 0)
    {
        string filename = AsyncStatus + "-" + AticketID + "-" + AsyncID + "-" + ApictureID;
        using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (ISF.FileExists(filename))
            {

                BitmapImage bmp = new BitmapImage();
                using (IsolatedStorageFileStream isoStream =
                    ISF.OpenFile(filename, System.IO.FileMode.Open))
                {
                    bmp.SetSource(isoStream);
                }
                ISF.DeleteFile(filename);
                WriteableBitmap Wbmp = new WriteableBitmap(bmp);
                using (IsolatedStorageFileStream isoStream =
                ISF.OpenFile(TsyncStatus + "-" + AticketID + "-" + TsyncID + "-" + ApictureID, System.IO.FileMode.Create))
                {
                    Extensions.SaveJpeg(Wbmp, isoStream,
                        Wbmp.PixelWidth,
                        Wbmp.PixelHeight,
                        0, 100);
                }


            }
        }
    }

该问题源于无法在UI线程之外实例化BitmapImage这一事实。您可以通过在Dispatcher Invoke调用中包装调用来修复此问题

但是,您需要确保正确调用NotifyComplete。因此,您可能需要在Dispatcher调用中输入NotifyComplete

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    UpdateSyncPictureName(...);
    NotifyComplete();
});

该问题源于无法在UI线程之外实例化BitmapImage这一事实。您可以通过在Dispatcher Invoke调用中包装调用来修复此问题

但是,您需要确保正确调用NotifyComplete。因此,您可能需要在Dispatcher调用中输入NotifyComplete

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    UpdateSyncPictureName(...);
    NotifyComplete();
});