我想使用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);”调用。 我只是想通过手机拍照,而且没有发送或接收操作。我不知道为什么接收功能被调用。
应用程序在跳转到相册时会丢失套接字通信(套接字的值“RemoteEndPoint”会变为null)吗?附: “socket”是类“Socket”的对象。 如果是这样,每次应用程序跳出时我都应该重新创建“套接字”吗?
谢谢!
答案 0 :(得分:0)
一旦调用了PhotoChooserTask,您的应用程序将是快速应用程序切换(或甚至可能是逻辑删除)。
您的套接字将被关闭。当您的应用再次激活时,您必须重新打开套接字。