|
You should also wrap the SqlConnection , SqlCommand and SqlDataReader objects in using blocks:
using (SqlConnection con = new SqlConnection(connectionString))
using (SqlCommand com = new SqlCommand("SELECT * FROM Graphik", con))
{
con.Open();
using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection))
{
...
}
}
This ensures that the resources get cleaned up even if there is an exception.
Also, unless you're using .NET 1.0 or 1.1, you should replace ArrayList with List<DbDataRecord> :
List<T> Class (System.Collections.Generic)[^]
Generics (C# Programming Guide)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi sir's/mam's
My question is somewhat simple to all i think but here is my problem. I have 2 program in c# using Visual Studio to program this software . But my problem is now i don't know how to merge/implement this both software and make it work.
2 programs are :
1 : uEye ActiveX Demo
2 : c# Socket threading socket programming (server only)
What Should it work for? (if you gonna ask)
=> it should work for connecting from client to server . the client will send a message , (probably an hexadecimal code), and the server will read and accept instruction to capture a picture and save it into the server's file folder it self.
so how to attach this both files and make it work?
Please Help
Below is the c# uEye ActiveX Demo program
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data;
namespace uEyeActiveXDemo_CS
{
/// <summary>
/// Zusammenfassung für Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button Init;
private System.Windows.Forms.Button Snap;
private System.Windows.Forms.Button Save;
private System.Windows.Forms.Button Properties;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton TriggerSoftware;
private System.Windows.Forms.RadioButton TriggerFalling;
private System.Windows.Forms.RadioButton TriggerRising;
private System.Windows.Forms.TextBox Info1;
private System.Windows.Forms.TextBox Info2;
private System.Windows.Forms.TextBox Info3;
private System.Windows.Forms.ListBox InfoList;
private bool m_bCameraOpen;
private bool m_bLive;
private Int64 m_MemAddr;
private byte[] rgb;
private bool m_bContinuousTriggerSupported;
private int m_nCurrentMode;
private int m_nTransferFailed;
private int m_nTransferFailedOld;
private Timer t1;
private System.Drawing.Point LastPoint;
private System.Windows.Forms.RadioButton TriggerOff;
private System.Windows.Forms.Button CaptureImage;
private System.Windows.Forms.CheckBox Direct3D;
private AxuEyeCamLib.AxuEyeCam axuEyeCam;
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
m_bCameraOpen = false;
rgb = new byte[3];
m_MemAddr = 0;
LastPoint = new System.Drawing.Point(0, 0);
m_nCurrentMode = 0;
m_nTransferFailed = 0;
m_nTransferFailedOld = 0;
t1 = new Timer();
t1.Interval = 100;
t1.Tick += new EventHandler(t1_Tick);
t1.Start();
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.Init = new System.Windows.Forms.Button();
this.Snap = new System.Windows.Forms.Button();
this.CaptureImage = new System.Windows.Forms.Button();
this.Save = new System.Windows.Forms.Button();
this.Properties = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.TriggerOff = new System.Windows.Forms.RadioButton();
this.TriggerRising = new System.Windows.Forms.RadioButton();
this.TriggerSoftware = new System.Windows.Forms.RadioButton();
this.TriggerFalling = new System.Windows.Forms.RadioButton();
this.Info1 = new System.Windows.Forms.TextBox();
this.Info2 = new System.Windows.Forms.TextBox();
this.Info3 = new System.Windows.Forms.TextBox();
this.InfoList = new System.Windows.Forms.ListBox();
this.Direct3D = new System.Windows.Forms.CheckBox();
this.axuEyeCam = new AxuEyeCamLib.AxuEyeCam();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axuEyeCam)).BeginInit();
this.SuspendLayout();
//
// Init
//
this.Init.Location = new System.Drawing.Point(8, 8);
this.Init.Name = "Init";
this.Init.Size = new System.Drawing.Size(128, 24);
this.Init.TabIndex = 0;
this.Init.Text = "Init Camera";
this.Init.Click += new System.EventHandler(this.Init_Click);
//
// Snap
//
this.Snap.Location = new System.Drawing.Point(8, 93);
this.Snap.Name = "Snap";
this.Snap.Size = new System.Drawing.Size(128, 24);
this.Snap.TabIndex = 3;
this.Snap.Text = "Freeze";
this.Snap.Click += new System.EventHandler(this.Snap_Click);
//
// CaptureImage
//
this.CaptureImage.Location = new System.Drawing.Point(8, 64);
this.CaptureImage.Name = "CaptureImage";
this.CaptureImage.Size = new System.Drawing.Size(128, 24);
this.CaptureImage.TabIndex = 2;
this.CaptureImage.Text = "Stop capture";
this.CaptureImage.Click += new System.EventHandler(this.Capture_Click);
//
// Save
//
this.Save.Location = new System.Drawing.Point(8, 36);
this.Save.Name = "Save";
this.Save.Size = new System.Drawing.Size(128, 24);
this.Save.TabIndex = 1;
this.Save.Text = "Save Image";
this.Save.Click += new System.EventHandler(this.Save_Click);
//
// Properties
//
this.Properties.Location = new System.Drawing.Point(8, 368);
this.Properties.Name = "Properties";
this.Properties.Size = new System.Drawing.Size(128, 24);
this.Properties.TabIndex = 11;
this.Properties.Text = "Properties";
this.Properties.Click += new System.EventHandler(this.Properties_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.TriggerOff);
this.groupBox1.Controls.Add(this.TriggerRising);
this.groupBox1.Controls.Add(this.TriggerSoftware);
this.groupBox1.Controls.Add(this.TriggerFalling);
this.groupBox1.Location = new System.Drawing.Point(8, 147);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 117);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Trigger mode";
//
// TriggerOff
//
this.TriggerOff.Location = new System.Drawing.Point(12, 24);
this.TriggerOff.Name = "TriggerOff";
this.TriggerOff.Size = new System.Drawing.Size(88, 16);
this.TriggerOff.TabIndex = 6;
this.TriggerOff.Text = "Off";
this.TriggerOff.Click += new System.EventHandler(this.TriggerOff_Click);
//
// TriggerRising
//
this.TriggerRising.Location = new System.Drawing.Point(12, 93);
this.TriggerRising.Name = "TriggerRising";
this.TriggerRising.Size = new System.Drawing.Size(88, 16);
this.TriggerRising.TabIndex = 9;
this.TriggerRising.Text = "Rising edge";
this.TriggerRising.Click += new System.EventHandler(this.TriggerRising_Click);
//
// TriggerSoftware
//
this.TriggerSoftware.Location = new System.Drawing.Point(12, 47);
this.TriggerSoftware.Name = "TriggerSoftware";
this.TriggerSoftware.Size = new System.Drawing.Size(80, 16);
this.TriggerSoftware.TabIndex = 7;
this.TriggerSoftware.Text = "Software";
this.TriggerSoftware.Click += new System.EventHandler(this.TriggerSoftware_Click);
//
// TriggerFalling
//
this.TriggerFalling.Location = new System.Drawing.Point(12, 70);
this.TriggerFalling.Name = "TriggerFalling";
this.TriggerFalling.Size = new System.Drawing.Size(96, 16);
this.TriggerFalling.TabIndex = 8;
this.TriggerFalling.Text = "Falling edge";
this.TriggerFalling.Click += new System.EventHandler(this.TriggerFalling_Click);
//
// Info1
//
this.Info1.Location = new System.Drawing.Point(144, 370);
this.Info1.Name = "Info1";
this.Info1.ReadOnly = true;
this.Info1.Size = new System.Drawing.Size(176, 20);
this.Info1.TabIndex = 9;
this.Info1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// Info2
//
this.Info2.Location = new System.Drawing.Point(320, 370);
this.Info2.Name = "Info2";
this.Info2.ReadOnly = true;
this.Info2.Size = new System.Drawing.Size(224, 20);
this.Info2.TabIndex = 10;
this.Info2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// Info3
//
this.Info3.Location = new System.Drawing.Point(544, 370);
this.Info3.Name = "Info3";
this.Info3.ReadOnly = true;
this.Info3.Size = new System.Drawing.Size(80, 20);
this.Info3.TabIndex = 15;
this.Info3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// InfoList
//
this.InfoList.Location = new System.Drawing.Point(8, 268);
this.InfoList.Name = "InfoList";
this.InfoList.SelectionMode = System.Windows.Forms.SelectionMode.None;
this.InfoList.Size = new System.Drawing.Size(128, 95);
this.InfoList.TabIndex = 10;
//
// Direct3D
//
this.Direct3D.Location = new System.Drawing.Point(20, 123);
this.Direct3D.Name = "Direct3D";
this.Direct3D.Size = new System.Drawing.Size(104, 20);
this.Direct3D.TabIndex = 4;
this.Direct3D.Text = "use Direct3D";
this.Direct3D.CheckedChanged += new System.EventHandler(this.Direct3D_CheckedChanged);
//
// axuEyeCam
//
this.axuEyeCam.Enabled = true;
this.axuEyeCam.Location = new System.Drawing.Point(144, 8);
this.axuEyeCam.Name = "axuEyeCam";
this.axuEyeCam.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axuEyeCam.OcxState")));
this.axuEyeCam.Size = new System.Drawing.Size(480, 355);
this.axuEyeCam.TabIndex = 16;
//
// Form1
//
this.AllowDrop = true;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(632, 396);
this.Controls.Add(this.axuEyeCam);
this.Controls.Add(this.Direct3D);
this.Controls.Add(this.Info3);
this.Controls.Add(this.Info2);
this.Controls.Add(this.Info1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.Properties);
this.Controls.Add(this.Save);
this.Controls.Add(this.CaptureImage);
this.Controls.Add(this.Snap);
this.Controls.Add(this.Init);
this.Controls.Add(this.InfoList);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "IDS uEye ActiveX";
this.Load += new System.EventHandler(this.Form1_Load);
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.axuEyeCam)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
UpdateControls( );
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
axuEyeCam.ExitCamera();
}
private void UpdateControls( )
{
Save.Enabled = m_bCameraOpen;
CaptureImage.Enabled = m_bCameraOpen;
Snap.Enabled = m_bCameraOpen;
Properties.Enabled = m_bCameraOpen;
TriggerOff.Enabled = m_bCameraOpen;
bool bTriggerSoftware = false;
bool bTriggerLoHi = false;
bool bTriggerHiLo = false;
m_bContinuousTriggerSupported = false;
if (m_bCameraOpen)
{
int nSupportedTriggerMode = axuEyeCam.SetExternalTrigger(uEye_defines.IS_GET_SUPPORTED_TRIGGER_MODE);
if ((nSupportedTriggerMode & uEye_defines.IS_SET_TRIG_SOFTWARE) == uEye_defines.IS_SET_TRIG_SOFTWARE)
{
bTriggerSoftware = true;
}
if ((nSupportedTriggerMode & uEye_defines.IS_SET_TRIG_LO_HI) == uEye_defines.IS_SET_TRIG_LO_HI)
{
bTriggerLoHi = true;
}
if ((nSupportedTriggerMode & uEye_defines.IS_SET_TRIG_HI_LO) == uEye_defines.IS_SET_TRIG_HI_LO)
{
bTriggerHiLo = true;
}
if ((nSupportedTriggerMode & uEye_defines.IS_SET_TRIGGER_CONTINUOUS) == uEye_defines.IS_SET_TRIGGER_CONTINUOUS)
{
m_bContinuousTriggerSupported = true;
}
}
TriggerSoftware.Enabled = m_bCameraOpen & bTriggerSoftware;
TriggerFalling.Enabled = m_bCameraOpen & bTriggerHiLo;
TriggerRising.Enabled = m_bCameraOpen & bTriggerLoHi;
if( m_bCameraOpen )
{
Init.Text = "Exit Camera";
Info1.Text = String.Format("{0} SerNo:{1}", axuEyeCam.GetSensorName(), axuEyeCam.GetSerialNumber());
Info2.Text = String.Format("{0} x {1}", axuEyeCam.GetImageWidth().ToString(), axuEyeCam.GetImageHeight().ToString() );
Direct3D.Checked = axuEyeCam.EnableDirect3D;
}
else
{
Init.Text = "Init Camera";
Info1.Text = String.Format("No open camera");
Info2.Text = "-";
Info3.Text = "0 fps";
TriggerOff.Checked = true;
}
if( axuEyeCam.EnableDirect3D )
{
Info2.Text = "Click to draw a cross!";
}
}
private void Init_Click(object sender, System.EventArgs e)
{
m_MemAddr = 0;
if( m_bCameraOpen )
{
axuEyeCam.ExitCamera();
m_bCameraOpen = false;
m_bLive = false;
// Disable events
axuEyeCam.EnableEvent( uEye_defines.IS_FRAME, 0 );
axuEyeCam.EnableEvent( uEye_defines.IS_DEVICE_REMOVED, 0 );
axuEyeCam.EnableEvent( uEye_defines.IS_TRANSFER_FAILED, 0 );
axuEyeCam.EnableEvent( uEye_defines.IS_TRIGGER, 0 );
axuEyeCam.EventOnFrame -= axuEyeCam_EventOnFrame;
axuEyeCam.EventOnTransferFailed -= axuEyeCam_EventOnTransferFailed;
axuEyeCam.MouseMoveEvent -= axuEyeCam_MouseMoveEvent;
axuEyeCam.MouseDownEvent -= axuEyeCam_MouseDownEvent;
}
else
{
int nRet = axuEyeCam.InitCamera (0);
if (nRet == uEye_defines.IS_STARTER_FW_UPLOAD_NEEDED)
{
int nUploadTime = 0;
axuEyeCam.GetDuration (uEye_defines.IS_STARTER_FW_UPLOAD, ref nUploadTime);
String Str;
Str = "This camera requires a new firmware. The upload will take about " + (nUploadTime / 1000).ToString() + " seconds.";
MessageBox.Show(Str);
nRet = axuEyeCam.InitCamera(0 | uEye_defines.IS_ALLOW_STARTER_FW_UPLOAD);
}
if (nRet == uEye_defines.IS_SUCCESS)
{
m_bCameraOpen = true;
m_bLive = true;
// Enable events
axuEyeCam.EnableEvent( uEye_defines.IS_FRAME, 1 );
axuEyeCam.EnableEvent( uEye_defines.IS_DEVICE_REMOVED, 1 );
axuEyeCam.EnableEvent( uEye_defines.IS_TRANSFER_FAILED, 1 );
axuEyeCam.EnableEvent( uEye_defines.IS_TRIGGER, 1 );
axuEyeCam.EventOnFrame += axuEyeCam_EventOnFrame;
axuEyeCam.EventOnTransferFailed += axuEyeCam_EventOnTransferFailed;
axuEyeCam.MouseMoveEvent += axuEyeCam_MouseMoveEvent;
axuEyeCam.MouseDownEvent += axuEyeCam_MouseDownEvent;
m_nTransferFailed = 0;
m_nTransferFailedOld = 0;
InfoList.Items.Clear();
InfoList.Items.Add( String.Format( "{0} opened!", axuEyeCam.GetSensorName() ));
// Set the trigger timeout to 5 s (500 = 5000 ms)
axuEyeCam.SetTimeout(uEye_defines.IS_TRIGGER_TIMEOUT, 500);
}
else
{
MessageBox.Show("Init failed","Could not open camera!");
}
}
UpdateControls( );
}
private void Snap_Click(object sender, System.EventArgs e)
{
axuEyeCam.FreezeImage(uEye_defines.IS_DONT_WAIT);
m_bLive = false;
CaptureImage.Text = "Start capture";
}
private void Capture_Click(object sender, System.EventArgs e)
{
if(m_bLive)
{
// Stop capture
axuEyeCam.StopLiveVideo(uEye_defines.IS_WAIT);
m_bLive = false;
CaptureImage.Text = "Start capture";
}
else
{
if (!m_bContinuousTriggerSupported && (TriggerOff.Checked == false))
{
// Stop capture
axuEyeCam.StopLiveVideo(uEye_defines.IS_WAIT);
m_bLive = false;
CaptureImage.Text = "Start capture";
MessageBox.Show("The continuous trigger mode is not supported by this camera");
}
else
{
// Start capture
axuEyeCam.StartLiveVideo(1);
m_bLive = true;
CaptureImage.Text = "Stop capture";
}
}
}
private void Save_Click(object sender, System.EventArgs e)
{
axuEyeCam.SaveImage("Test.jpg");
}
private void Properties_Click(object sender, System.EventArgs e)
{
axuEyeCam.PropertyDialog();
UpdateControls();
}
private void Direct3D_CheckedChanged(object sender, System.EventArgs e)
{
axuEyeCam.EnableDirect3D = Direct3D.Checked;
UpdateControls();
}
private void axuEyeCam_EventOnTrigger(object sender, System.EventArgs e)
{
}
private void axuEyeCam_EventOnTransferFailed(object sender, System.EventArgs e)
{
m_nTransferFailed++;
}
void t1_Tick(object sender, EventArgs e)
{
if (m_bCameraOpen && (m_nTransferFailedOld != m_nTransferFailed))
{
String str;
str = "Transfer failed: " + m_nTransferFailed;
InfoList.Items.Add(str);
m_nTransferFailedOld = m_nTransferFailed;
}
}
private delegate void UpdateFPS();
private void ShowFPS()
{
Info3.Text = String.Format(" {0} fps ", axuEyeCam.GetFramesPerSecond().ToString().Substring(0, 5));
}
private void axuEyeCam_EventOnFrame(object sender, AxuEyeCamLib._DuEyeCamEvents_EventOnFrameEvent e)
{
Info3.Invoke(new UpdateFPS(ShowFPS));
m_MemAddr = System.Convert.ToInt64(axuEyeCam.GetImageMem());
}
private void axuEyeCam_MouseMoveEvent(object sender, AxuEyeCamLib._DuEyeCamEvents_MouseMoveEvent e)
{
if( m_bCameraOpen && !axuEyeCam.EnableDirect3D )
{
int x = 0, y = 0;
int width = 0, height = 0, bits = 0, pitch = 0;
axuEyeCam.InquireImageMem( ref width, ref height, ref bits, ref pitch );
if( axuEyeCam.InitFitToWindow )
{
x = e.x * width / axuEyeCam.Size.Width;
y = e.y * height / axuEyeCam.Size.Height;
}
else
{
x = e.x;
y = e.y;
}
if( (x < 0) || (x > width) || (y < 0) || (y > height) )
{
Info2.Text = String.Format("Invalid position");
return;
}
if (this.m_MemAddr != 0)
{
// try to get the rgb values (in case of 24 or 32 bit images)
// on Y8 images you got 3 Y values
try
{
rgb[0] = Marshal.ReadByte( (IntPtr)this.m_MemAddr, (y*width + x)*bits/8 );
rgb[1] = Marshal.ReadByte( (IntPtr)this.m_MemAddr, (y*width + x)*bits/8 + 1 );
rgb[2] = Marshal.ReadByte( (IntPtr)this.m_MemAddr, (y*width + x)*bits/8 + 2 );
}
catch(Exception ee)
{
Console.WriteLine("ScanForm : " + ee.Message + " Type : " + ee.GetType().ToString());
}
Info2.Text = String.Format(" ({0},{1}) = ({2},{3},{4})", x, y, rgb[0], rgb[1], rgb[2] );
} // end if (this.m_MemAddr != 0)
else
{
Info2.Text = String.Format(" ({0},{1}) = (N/A)", x, y);
}
}
}
private void axuEyeCam_EventOnDeviceRemoved(object sender, System.EventArgs e)
{
// Enable reconnect message
axuEyeCam.EnableEvent( uEye_defines.IS_DEVICE_RECONNECTED, 1 );
InfoList.Items.Add( String.Format( "Camera disconnected!"));
Info1.Text = "Camera disconnected!!";
}
private void axuEyeCam_EventOnDeviceReconnected(object sender, System.EventArgs e)
{
// Disable reconnect message
axuEyeCam.EnableEvent( uEye_defines.IS_DEVICE_RECONNECTED, 0 );
InfoList.Items.Add( String.Format( "Camera reconnected!"));
UpdateControls();
}
private void axuEyeCam_Error(object sender, AxuEyeCamLib._DuEyeCamEvents_ErrorEvent e)
{
InfoList.Items.Add( String.Format( "Error No.{0}, {1}", e.number, e.description ) );
}
private void axuEyeCam_MouseDownEvent(object sender, AxuEyeCamLib._DuEyeCamEvents_MouseDownEvent e)
{
if( axuEyeCam.EnableDirect3D && m_bCameraOpen )
{
System.Drawing.Point p = new System.Drawing.Point( e.x, e.y );
DrawCross (p);
axuEyeCam.ShowDirect3DOverlay = true;
}
}
private void DrawCross (System.Drawing.Point e )
{
// Get the size of the display window
int nDisplayHeight = axuEyeCam.Height;
int nDisplayWidth = axuEyeCam.Width;
int nImageHeight = 0;
int nImageWidth = 0;
// Get the image size
axuEyeCam.GetImageSize(ref nImageWidth, ref nImageHeight);
double dblScaleFactorX = 1.0;
double dblScaleFactorY = 1.0;
// Calculate the scaling factors between the image and the display
// to show a cross with the correct size
if ((axuEyeCam.GetRenderMode() & uEye_defines.IS_RENDER_FIT_TO_WINDOW) != 0)
{
dblScaleFactorX = (double)nImageWidth / (double)nDisplayWidth;
dblScaleFactorY = (double)nImageHeight / (double)nDisplayHeight;
}
// Create a pen with the color red
System.Drawing.SolidBrush brush;
brush = new System.Drawing.SolidBrush (System.Drawing.Color.Red);
System.Drawing.Pen pen = new System.Drawing.Pen( brush, 3) ;
// Calculate the correct position of the cross (depending on the scaling factors)
int x = (int)((double)e.X * dblScaleFactorX);
int y = (int)((double)e.Y * dblScaleFactorY);
// Calculate the correct width and height of the cross
int nCrossWidth = (int)(10 * dblScaleFactorX);
int nCrossHeight = (int)(10 * dblScaleFactorY);
System.Drawing.Point pt1 = new System.Drawing.Point( x - nCrossWidth, y - nCrossHeight );
System.Drawing.Point pt2 = new System.Drawing.Point( x + nCrossWidth, y + nCrossHeight );
System.Drawing.Point pt3 = new System.Drawing.Point( x + nCrossWidth, y - nCrossHeight );
System.Drawing.Point pt4 = new System.Drawing.Point( x - nCrossWidth, y + nCrossHeight );
// Set the Direct3D key color to black
axuEyeCam.Direct3DKeyColor = System.Drawing.Color.Black;
// Clear the Direct3D overlay
axuEyeCam.ClearDirect3DOverlay ();
// Get the DC of the Direct3D overlay
int hdc = axuEyeCam.GetDC();
System.Drawing.Graphics DC = System.Drawing.Graphics.FromHdc( (System.IntPtr)hdc );
DC.DrawLine( pen, pt1, pt2 );
DC.DrawLine( pen, pt3, pt4 );
// Release the DC of the Direct3D overlay
axuEyeCam.ReleaseDC( hdc );
}
private void TriggerOff_Click(object sender, System.EventArgs e)
{
if(m_bLive)
{
axuEyeCam.StopLiveVideo( uEye_defines.IS_WAIT );
}
// Disable trigger
if (axuEyeCam.SetExternalTrigger(uEye_defines.IS_SET_TRIGGER_OFF) != uEye_defines.IS_SUCCESS)
{
if (m_nCurrentMode == 1)
{
TriggerOff.Checked = false;
TriggerSoftware.Checked = true;
TriggerRising.Checked = false;
TriggerFalling.Checked = false;
}
else if (m_nCurrentMode == 2)
{
TriggerOff.Checked = false;
TriggerSoftware.Checked = false;
TriggerRising.Checked = false;
TriggerFalling.Checked = true;
}
else if (m_nCurrentMode == 3)
{
TriggerOff.Checked = false;
TriggerSoftware.Checked = false;
TriggerRising.Checked = true;
TriggerFalling.Checked = false;
}
MessageBox.Show("The trigger mode can not be disabled with the current settings");
return;
}
if(m_bLive)
{
axuEyeCam.StartLiveVideo(1);
}
m_nCurrentMode = 0;
}
private void TriggerSoftware_Click(object sender, System.EventArgs e)
{
if(m_bLive)
{
axuEyeCam.StopLiveVideo( uEye_defines.IS_WAIT );
}
// Enable software trigger
axuEyeCam.SetExternalTrigger( uEye_defines.IS_SET_TRIGGER_SOFTWARE );
if(m_bLive)
{
if (m_bContinuousTriggerSupported)
{
axuEyeCam.StartLiveVideo(1);
}
else
{
// Stop capture
axuEyeCam.StopLiveVideo(uEye_defines.IS_WAIT);
m_bLive = false;
CaptureImage.Text = "Start capture";
}
}
m_nCurrentMode = 1;
}
private void TriggerFalling_Click(object sender, System.EventArgs e)
{
if(m_bLive)
{
axuEyeCam.StopLiveVideo( uEye_defines.IS_WAIT );
}
// Enable hardware trigger falling
axuEyeCam.SetExternalTrigger( uEye_defines.IS_SET_TRIGGER_HI_LO );
if(m_bLive)
{
axuEyeCam.StartLiveVideoWait(100);
}
m_nCurrentMode = 2;
}
private void TriggerRising_Click(object sender, System.EventArgs e)
{
if(m_bLive)
{
axuEyeCam.StopLiveVideo( uEye_defines.IS_WAIT );
}
// Enable hardware trigger rising
axuEyeCam.SetExternalTrigger( uEye_defines.IS_SET_TRIGGER_LO_HI );
if(m_bLive)
{
axuEyeCam.StartLiveVideoWait(100);
}
m_nCurrentMode = 3;
}
}
}
Next one will be the c# socket programming for server only
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
public class ThreadedTcpSrvr {
private TcpListener client;
public ThreadedTcpSrvr()
{
client = new TcpListener(9050);
client.Start();
<pre>
Console.WriteLine("Waiting for clients...");
while(true)
{
while (!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new ConnectionThread();
newconnection.threadListener = this.client;
Thread newthread = new Thread(new
ThreadStart(newconnection.HandleConnection));
newthread.Start();
}
}
public static void Main()
{
ThreadedTcpSrvr server = new ThreadedTcpSrvr();
}
}
class ConnectionThread
{
public TcpListener threadListener;
private static int connections = 0;
public void HandleConnection()
{
int recv;
byte[] data = new byte[1024];
TcpClient client = threadListener.AcceptTcpClient();
NetworkStream ns = client.GetStream();
connections++;
Console.WriteLine("New client accepted: {0} active connections",
connections);
string welcome = "Welcome to my test server";
data = Encoding.ASCII.GetBytes(welcome);
ns.Write(data, 0, data.Length);
while(true)
{
data = new byte[1024];
recv = ns.Read(data, 0, data.Length);
if (recv == 0)
break;
ns.Write(data, 0, recv);
for (int i=0; i<data.length;i++) {
="" console.write(data[i]);
="" if="" (data[i]="=" 0x03)="" break;
="" }
="" console.writeline();
="" ns.close();
="" client.close();
="" connections--;
="" console.writeline("client="" disconnected:="" {0}="" active="" connections",
="" connections);
="" }
}
<="" pre="">
|
|
|
|
|
That is a code dump - and one that tells us nothing about your actual problem.
I'm guessing that you have found some code on the internet which you think will do what you want, but you have no idea how to use it or integrate it into your app - but I can;t be sure.
If that is the case, then that's down to you - we aren't here to deal with that kind of thing.
If it isn't, then get rid of the code dump, explain what you have tried, where you are stuck, what help you need. And only show us the code fragments relevant to that!
Would you want to wade through that lot without that info? Because I don't!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Member 11534552 wrote: and the server will read and accept instruction to capture a picture and save it into the server's file folder it self. Are you assuming that the server can take a picture using the clients webcam?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The program is basicly a big search and replace tool and is a fantastic tool for removing spyware from programs like Firefox or Sware-iron and works by scanning all the files in a folder and sub folder to look for strings that have "http://" in them or look like a domain name and ends in "acb.com" or "abc.org"
The program flags up suspect links using a system of coloured flags and then offers the chance for the user to bulk replace the Url with a new value so long as the length of the replacement is the same length as the old one or else the machine code in the dlls/exe's would end up crashing
did you know that if you scanned the file system for a browser like Chrome that you would find about 20,000 urls within the folder ?
A Simple replace of "Google.com" for "Gxxgle.com" Soon stops the browser from calling home and I also give the same treatment to Microsoft code.
So whats wrong apart from me not having the time.
Well the program does not do a scan and indexes the sections within each file that contains a URL and needs to re-read each file (could be hundreds) each time a replacement is made which makes it slow since it only does a search and replace for one string at a time.
it could do with an index or something more simple like an array of text to be searched and replaces like.
Google.com,Gxxgle.com
Microsoft.com,SlowSoft.com
Youtube.com,OurTube.com
The program backs up the root folder before it runs because sometimes it will crash the program being "Fixed" because the strings being replaced are too short because i am lazzy and this would happen if you tried to fix google chrome by replacing "Google.com" and not using something more like "https://Google.com/SafeBrowsing"
I can play around because i wrote the program which work on all the major browsers i have come across so far after a few roll-backs due to the problems i have mentioned above but it needs to be made more fool proof so that anyone can use it as and when new versions of programs are released.
The program has resulted in my DNS server being full of bad DNS results 24/7 because programs like browsers are trying to call home two hundred times a day and thats just the way i like it.
Witten in c# and VS2010 if anyone would like to take it on then please drop me a line for the project.
|
|
|
|
|
|
I wouldn't really trust an application that claims to perform a search-and-replace in the binaries
Block them in the host-file or over the proxy.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am supposed to create a C# solution to compare the data (table, column and row) from two different databases and update the 2nd one as follows:
1. with just the rows that are updated recently (incase of duplicates)
2. check for new/updated column in 1st one and update/delete in 2nd accordingly or drop the table entirely and copy it from 1st one.
3. check for new/updated table in 1st one and update/delete in 2nd accordingly or drop the table entirely and copy it from 1st one.
So basically I have to synchronize the data between the two databases.
As of now, I have just got to connecting the database part. I am not sure how to proceed (should I be dumping the data from the database and checking or is there a simpler way?).!!!
Any help would be appreciated.
Thank you!
|
|
|
|
|
|
Anyone knows how to handle timeout operation in task class in C#. I meant after a particular time of task progress , the current task should be disposed and another task with the same arguments should be started.
|
|
|
|
|
There's an excellent discussion about adding the ability to TimeoutAfter in this[^] article.
|
|
|
|
|
You could possibly use Timers, or if you meant the Exception then you should use try catch block. Share some more information about context please.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Is there a good looking way of receiving an object reference instead of a new object with the linq extension methods? Id like the two code lines below to update the object within the salesLst.
ProdTotalSales ps = salesLst.First(p => p.Month == o.OrderDatum.Month);
ps.Antal += r.BestSaldo;
|
|
|
|
|
It does!
public class ProdTotalSales
{
public string Text { get; set; }
public int Value { get; set; }
public ProdTotalSales(string s, int i)
{
Text = s;
Value = i;
}
public override string ToString()
{
return string.Format("{0}:{1}", Value, Text);
}
}
ProdTotalSales p1 = new ProdTotalSales("P1", 1);
ProdTotalSales p2 = new ProdTotalSales("P2", 2);
List<ProdTotalSales> list = new List<ProdTotalSales>() { p1, p2 };
Console.WriteLine("Before:");
foreach (ProdTotalSales p in list) Console.WriteLine(p);
ProdTotalSales pn = list.First(p => p.Value == 2);
pn.Text = "P2 Modified";
Console.WriteLine("After:");
foreach (ProdTotalSales p in list) Console.WriteLine(p);
Before:
1:P1
2:P2
After:
1:P1
2:P2 Modified
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Well, I made the classic mistake of attaching too little code to my question, sorry about that. The thing is that my ProdTotalSales was declared as a struct. That meant that when I was debugging, the debugger showed ps.Antal=1 but salesLst[0].Antal=0 after executing the two rows of code above. I still dont understand how that could be. Now when I changed the ProdTotalSales into being a class, it works just fine. I would really appreciate an explanation to this. Could it have something to do with me calling the default-constructor?
The ProdTotalSales looked like this:
public struct ProdTotalSales
{
public int Year { get; set; }
public int Month { get; set; }
public int Antal { get; set; }
public ProdTotalSales(int _year, int _month, int _antal) : this()
{
Year = _year;
Month = _month;
Antal = _antal;
}
}
|
|
|
|
|
Ah! As you say, too little code!
The thing is that a struct is always a Value type, and a class a Reference type - which means that when you assign a struct instance to another variable you always get a copy, not a reference to the existing one - and it doesn't matter if you do it directly:
ProdTotalSales pn = list[0]
Or via a Linq method:
ProdTotalSales pn = list.First(p => p.Value == 2);
You always get a copy of the data, not a reference to the original item.
I wrote an article on the difference last year: Using struct and class - what's that all about?[^] which may help.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yes, should have thought of that. I know the struct is a value typ, though didnt think of the implications of it. Thanks for the explanation, and Ill take a peek at your article.
|
|
|
|
|
TMattC wrote: didnt think of the implications of it.
You never do until it bites you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
after looking at this MSDN: Struct[^]
is shows that struct is a value type hence how it behaves different to a class in this situation.
way around your issue I am not sure at the moment.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Hi!
I have made a c# program that writes a binary file of approximately 16 MB, then proceeds to process the file by reading and writing individual bytes after specific rules.
Generating the inital file runs without any issues, but when the actual processing starts, so do my problems:
Test application:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FileStream Stream = new FileStream("test.file", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
int i;
int NumReads, NumWrites;
NumReads = 0;
NumWrites = 0;
for (i = 0; i < 1024 * 1024; i++)
{
Stream.WriteByte(0);
NumWrites++;
}
while (true)
{
for (i = 0; i < Stream.Length; i++)
{
Stream.Position = i;
int x=Stream.ReadByte();
NumReads++;
if (i % 16 == 0)
{
Stream.Position = i + 8;
int y = Stream.ReadByte();
NumReads++;
Stream.Position = i + 10;
Stream.WriteByte(1);
NumWrites++;
}
}
Console.WriteLine("Loop done. Reads="+NumReads.ToString()+", Writes="+NumWrites.ToString());
ConsoleKeyInfo result = Console.ReadKey();
if (result.Key==ConsoleKey.Escape) break;
}
Stream.Close();
}
}
} The process is painfully slow, and the program appears to be reading huge amounts of data during the process, according to Task Manager, during program execution, it looks like the program is reading 300 MB/second, or more, which is about what my HDD can do. The number of writes performed are looking normal.
I have tried implementing counters for read and write operations, and these seem to match what I am trying to do.
I have tried lots of different buffer sizes when initializing the FileStream, but the results are the same.
I dont know whether it is Task Manager being off, or c# actually messing up I/O so badly.
Does anybody have any idea what is going on ?
Thanks in advance,
Dan
modified 2-Apr-15 1:15am.
|
|
|
|
|
Most of your code seems to be missing from that post. Use the "Edit" link to update the post with the missing code.
Also, you should wrap your code in <pre lang="cs"> ... </pre> tags, or use a fenced code block:
<pre lang="cs">
Your code goes here...
</pre>
-or-
```cs
Your code goes here...
```
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry about that, and thanks for showing me how to do it properly, my post has been updated.
|
|
|
|
|
I think you forgot some code there. You may also want to use a code block for the code.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|