1

我想像这样使用 PhotoChooserTask 返回一张照片:

 private void getimage_Click(object sender, EventArgs e)
     {
         photoChooserTask = new PhotoChooserTask();
         photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);

         try
         {
             photoChooserTask.Show();
         }
         catch (System.InvalidOperationException ex)
         {
             MessageBox.Show("An error occurred.");
         }

     }
     void photoChooserTask_Completed(object sender, PhotoResult ee)
     {
         if (ee.TaskResult == TaskResult.OK)
         {

             BitmapImage bmp = new BitmapImage();
             bmp.SetSource(ee.ChosenPhoto);

             if (ee.TaskResult == TaskResult.OK && ee.Error == null)
             {

                     WriteableBitmap wb = new WriteableBitmap(bmp);

                     notes.Add(new chatinfo() { sendimage = bmp });
                     noteListBox.ItemsSource = null;
                     noteListBox.ItemsSource = notes;
             }
           }

       }

但每次程序到达这里:“bmp.SetSource(ee.ChosenPhoto);” 将调用 SocketException。

private void OnRecieveFrom()
     {
         var receiveArgs = new SocketAsyncEventArgs();
         receiveArgs.RemoteEndPoint = this.IPEndPoint;
         receiveArgs.SetBuffer(new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
         var strBdr = new StringBuilder();
         receiveArgs.Completed += (__, result) =>
         {

             string message = CreateMessage(result);

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                 {
                     this.RaiseReceived(message);

                 });
                 socket.ReceiveFromAsync(receiveArgs);    



         };

             socket.ReceiveFromAsync(receiveArgs);


     }

SocketException 由“socket.ReceiveFromAsync(receiveArgs);”调用 我只是想从手机中获取照片,没有发送或接收操作。我不知道为什么调用接收函数。

应用跳转到相册时会不会丢失socket通信(socket的“RemoteEndPoint”值变为null)?ps “socket”是“Socket”类的一个对象。如果是这样,我应该在每次应用程序跳出时重新创建“套接字”吗?

谢谢!

4

1 回答 1

0

一旦调用 PhotoChooserTask,您的应用程序将被快速应用程序切换(甚至可能被墓碑化)。

无论哪种方式,您的套接字都将关闭。当您的应用再次激活时,您必须重新打开您的套接字。

于 2012-12-12T11:47:56.600 回答