[英]Async error of {“Parameter is not valid.”} when working with windows forms
I have a simple windows form that has a button to click that loads a listbox of named elevations, when one of the elevations are clicked on the id belonging to that elevation is passed to a function that creates a bitmap and returns it to the original calling function. 我有一个简单的Windows窗体,有一个单击按钮,它会加载一个名为高程的列表框,当在属于该高程的ID上单击其中一个高程时,将传递给创建位图并将其返回到原始调用的函数。功能。 I keep getting these weird errors. 我不断收到这些奇怪的错误。
I keep getting a {"Parameter is not valid."} error. 我不断收到{“参数无效。”}错误。
Any ideas as to whats going on here? 关于这里发生的事情有什么想法吗?
I've also added two screen shots, one of the Window Form and one of the error. 我还添加了两个屏幕快照,一个是“窗口窗体”,另一个是错误。
async void lbElevations_MouseClick(object sender, MouseEventArgs e)
{
var bitmapElevation = await ShowElevation();
}
async Task<Bitmap> ShowElevation()
{
int id = int.Parse(this.lbElevations.SelectedValue.ToString());
bool isPDF = false;
Bitmap bitElevation = new Bitmap(0, 0);
bool Rotate90 = false;
string action = "getelevation";
IElevation elev = await ElevationManagerDL.GetElevationAsync(id);
action = action.ToLower();
RotateFlipType rotateFlip = Rotate90 ? RotateFlipType.Rotate90FlipNone : RotateFlipType.RotateNoneFlipNone;
//elevation / shop drawing
if (action == "getelevation")
{
#region Just Elevation
if (isPDF)
{
using (var pdf = await AlumCloudPlansBL.Manager.GetElevationPDFAsync(elev, true))
{
//pdf
}
}
else
{
using (bitElevation = await AlumCloudPlansBL.Manager.GetElevationDrawingAsync(elev, true, rotateFlip, false))
{
//canvas
}
}
#endregion
}
return bitElevation;
}
The problem you are having is that you are constructing a bitmap with 0 height and width: 您遇到的问题是您正在构建高度和宽度为0的位图:
The following code will also raise the exception: 以下代码也会引发异常:
try
{
Bitmap b = new Bitmap(0, 0);
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.ToString());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.