我在winfroms中构建了一个自定义UserControl,并通过辅助线程将其添加到Panel中.
我知道当通过辅助线程添加控件时,您需要调用主线程来执行它.所以我做了..但我仍然得到一个例外,说"跨线程操作无效:控制'pictureBoxImage'从一个线程访问,而不是它创建的线程."
我被卡住了,不知道是什么导致了这个因为我尝试通过在每个自定义UserControl方法上放置一个断点来调试它,但是它们中的任何一个都没有引发异常.
private void addControl(Control i_ControllToAdd, Control i_ParentControl)
{
if (i_ParentControl.InvokeRequired)
{
i_ParentControl.Invoke(new Action(() => addControl(i_ControllToAdd, i_ParentControl)));
return;
}
i_ParentControl.Controls.Add(i_ControllToAdd);
}
Run Code Online (Sandbox Code Playgroud)
这是自定义的UserControl类
public partial class FBPostUserControl : UserControl
{
private readonly string m_UserName = string.Empty;
private readonly Image m_UserProfileImage = null;
private readonly DateTime? m_DatePosted = null;
private Image m_Image = null;
private string m_PostBody = string.Empty;
public string UserName
{
get { return m_UserName; }
}
public DateTime? DatePosted
{
get { return m_DatePosted; }
}
public Image …Run Code Online (Sandbox Code Playgroud) I'm trying to declare this kind of variable:
float[][]
Run Code Online (Sandbox Code Playgroud)
Things that didn't work for me (wouldn't compile) -
float[][] inputs = new float[10][5];
float[][] inputs = new float[10,5];
Run Code Online (Sandbox Code Playgroud)
When trying to declare the array like this -
int a = 3;
int b = 2;
float[][] inputs = new float[][]
{
new float[a],
new float[b]
};
Run Code Online (Sandbox Code Playgroud)
I get a multidimensional array with two float arrays instead of an array that has 3 arrays and every array size is 2.