【发布时间】:2015-08-10 17:35:12
【问题描述】:
我想使用下面的代码从表中获取所有数据:
CameraBUS cameraBus = new CameraBUS(); //Contain class provider access to DAO for GetByAllCamera.
DataTable dt = cameraBus.Camera_GetByAllCamera(); //select * from table Camera
foreach (DataRow row in dt.Rows)
{
CameraDTO camera = new CameraDTO(row);
if(camera.IDKhuVuc == 4)
{
OpenCamera(camera.ViTri, camera.TaiKhoan, camera.MatKhau, camera.IP);
}
if(camera.IDKhuVuc == 3)
{
OpenCamera(camera.ViTri, camera.TaiKhoan, camera.MatKhau, camera.IP);
}
}
如果 camera.IDKhuVuc 有 7 行或更多行。它总是启动 StartThead1 并且我的程序停止工作。 示例:
我的数据有 4 行,但此代码无法获取 4 行 4 个摄像头。它只打开第一个和最后一个摄像头。
当我调试我的程序时,它运行 2 行(第 2、3 行)。但是当我运行我的程序时,它并没有打开摄像头 2 和摄像头 3。
我想我应该使用 List 或数组。我该如何解决这个问题?
班级OpenCamera():
private void OpenCamera(bool position, string username, string password, string ipAddress)
{
if (!position)
{
axLiveX1.IpAddress = ipAddress;
axLiveX1.UserName = username;
axLiveX1.Password = password;
axLiveX1.DataPort = 5550;
axLiveX1.CommandPort = 4550;
axLiveX1.AudioDataPort = 6550;
axLiveX1.DefaultCam = 8;
axLiveX1.OnGetPicture += new AxLIVEXLib._DLiveXEvents_OnGetPictureEventHandler(axLiveX1_OnGetPicture);
axLiveX1.AutoLogin = true;
if (axLiveX1.Connect())
{
}
axLiveX1.StartGrapImage(true);
axLiveX2.IpAddress = ipAddress;
axLiveX2.UserName = username;
axLiveX2.Password = password;
axLiveX2.DataPort = 5550;
axLiveX2.CommandPort = 4550;
axLiveX2.AudioDataPort = 6550;
axLiveX2.DefaultCam = 8;
axLiveX2.OnGetPicture += new AxLIVEXLib._DLiveXEvents_OnGetPictureEventHandler(axLiveX2_OnGetPicture);
axLiveX2.AutoLogin = true;
axLiveX2.Connect();
axLiveX2.StartGrapImage(true);
}
else
{
axLiveX3.IpAddress = ipAddress;
axLiveX3.UserName = username;
axLiveX3.Password = password;
axLiveX3.DataPort = 5550;
axLiveX3.CommandPort = 4550;
axLiveX3.AudioDataPort = 6550;
axLiveX3.DefaultCam = 8;
axLiveX3.OnGetPicture += new AxLIVEXLib._DLiveXEvents_OnGetPictureEventHandler(axLiveX3_OnGetPicture);
axLiveX3.AutoLogin = true;
axLiveX3.Connect();
axLiveX3.StartGrapImage(true);
axLiveX4.IpAddress = ipAddress;
axLiveX4.UserName = username;
axLiveX4.Password = password;
axLiveX4.DataPort = 5550;
axLiveX4.CommandPort = 4550;
axLiveX4.AudioDataPort = 6550;
axLiveX4.DefaultCam = 8;
axLiveX4.OnGetPicture += new AxLIVEXLib._DLiveXEvents_OnGetPictureEventHandler(axLiveX4_OnGetPicture);
axLiveX4.AutoLogin = true;
axLiveX4.Connect();
axLiveX4.StartGrapImage(true);
}
}
【问题讨论】: