|
It should be noted that Windows is not a realtime OS and .Net is not a realtime API framework and will not respond properly if you need true realtime behavior in your threading and processing. If you need true realtime behavior you need to find another system.
Beyond this, without actually knowing percisely what you are trying to do I can only guess as to what to do or are trying to do. If you need to save perodically use a custom built threaded queue or use ThreadPool to spawn new threads to save data. You don't want to suspend saving in the middle or you'll have messed up data in the context before and after the suspend which means that this will break any realtime response.
As for using Application.Idle :
private void idle(object sender,EventArgs e)
{
System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(SaveStuff), stuff))
}
private static void SaveStuff(object state)
{
SaveStateStuff stuff = state as SaveStateStuff;
stuff.Save();
}
* this assumes SaveStateStuff is MT safe.
|
|
|
|
|
Hi,
I'm new to C# and I'm stuck with a problem
I'm trying to write a vector-based drawing program but I don't know how to scale the shapes or move them by the mouse..
I've used the serialization way to draw objects, as Budi Kuraniwan's tutorial in O'Reilly Network
http://www.oreillynet.com/lpt/a/2495[^]
My main question is how to manipulate shapes' properties from its array?
Like pen width, colour, size and position
If I change a shape property using the matrix statement, it doesn’t delete the old shape..
How to delete shapes from my draw area without clearing the whole page?
And how to Hit Test.. And select objects?
I've found an example in The Code Project website (Draw Tools) but its too complicated for a beginner like me..
http://www.codeproject.com/csharp/DrawTools.asp[^]
I’m trying to do a similar application
Thank you!
|
|
|
|
|
This is a simple matter of abstraction. You define a general Shape class, for example, from which each shape derives. On that you define general properties like the bounding rectangle, perhaps an ID, connection points, etc.
To move those shapes your container, or drawing surface, need to handle the MouseDown , MouseMove , and MouseUp events. When a user clicks, you use the coordinates and loop through the array finding the shape that contains those coordinates (the Rectangle.Contains method is handy in this case). While the mouse is down (use a simple state variable that gets reset in your MouseUp handler) change the location of the image as the user drags.
You extend a base class because you can implement helper methods in a single class. The container just needs to worry about positioning and sizing while the shapes worry about drawing themselves (the dumber the container is, the more extensible your solution is).
To scale individual images you need to implement functionality in either the shape or the container to size it. You can use the mouse techniques above to do that as well. Define a threshold and when the mouse is within that threshold and near the edge of a shape you can resize it. If you want to resize the whole drawing surface, you can apply a scale transform in your OnPaint override using the Graphics.ScaleTransform method.
This is not an easy subject and I recommend you start off with basic functionality. If the article you found is too complicated (welcome to the reality of application development) then I suggest picking up some object-oriented development books or reading additional articles. Eventually it will start making sense.
Be sure to read, however, because just using IntelliSense like I see far too many people doing in lieu of reading documentation won't teach you anything. When someone mentions classes, methods, properties, etc. that you're not familiar with (like I did above several times) find them in the .NET Framework SDK that is installed by default with VS.NET and is available online at http://msdn.microsoft.com/library[^] and read about them.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi folks,
My class library calls for me to constantly parse information sent to me by a server, and to do that I am currently using Socket.BeginReceive and Socket.EndReceive for my needs.
This is working fine. The only problem I am having is the threading design issues.
Whenever information comes in from the server I parse it and fire appropriate events based on the information received. The issue is that these events are fired using the worker thread that my callback was invoked on, not the client thread.
The question I'm asking is should I be taking steps to ensure that all of my events are being fired on the main client thread? If so, how? Or should I be looking at a different design altogether?
I would appreciate any advice anyone could offer
Thanks!
This space for rent!
My Blog
|
|
|
|
|
It depends on what you are doing when handling the events. If you want to show the status in your GUI you should not directly change it from a different thread than the one in which the GUI was created. To perform this and cross the thread borders look at the documentation of the function Control.Invoke. If no GUI is affected there is (in my opinion) no necessisty to make those changes. Just make sure everything is synchronized
|
|
|
|
|
Just a small addition to the previous answer:
Also take a look at the InvokeRequired property of the Control class, which helps to determine whether an invoke method must be called or not.
www.troschuetz.de
|
|
|
|
|
I looked at ISynchronizeInvoke, but I wasn't sure if it would meet my needs because I don't know if the objects of the class libray will be called from the UI thread or another thread. The library will be freely distributable, so I can't assume it will always be used from a UI thread.
Thanks for your comments!
This space for rent!
My Blog
|
|
|
|
|
The following code snippet:
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
string[] filenames=new string[] {dragImageFilename};
DataObject data=new DataObject(DataFormats.FileDrop, filenames);
((Control)sender).DoDragDrop(data, DragDropEffects.Copy);
dragging=false;
}
}
Behaves strangely. If I drop the object on the originating form (something I'm going to disallow later) then the DragEventArgs.Data is of type SystemWindows.Forms.DataObject and all is happy.
If I drag the object onto another instance of the exact same application, then DragEventArgs.Data is of type System.__ComObject.
The code that handles the drop does this:
Array data=((DataObject)e.Data).GetData("FileDrop") as Array;
Expecting a DataObject for e.Data. How do send/receive the data so that it's a DataObject and not a ComObject?
Thanks!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
"__ComObject" is an internal class of the mscorelib. Im not 100% sure but I think its a COM wrapper for the remoting mechanisms of .Net. It inherits from "MarshalByRefObject" so its probably the best way to first cast your data into this class and try to go further from here.
But this is probably more than you want to achieve. I think you dont want to do remote calls between your two application instances - just pass some data. You should probably pass the data in some binary - or even better XML - format and make the serialization and deserialization by yourself.
|
|
|
|
|
Hi Robert,
Thanks, that helped to set me on the right path. The correct decoding has to be done as:
Array data=((IDataObject)e.Data).GetData("FileDrop") as Array;
rather than:
Array data=((DataObject)e.Data).GetData("FileDrop") as Array;
Oh, what a difference an "I" makes!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Hi
I would like to find how much time passed between two points in the program.
the problem is that if the system clock was modified between the two points and I subtract the time of the first point from the time of the second time I will get a wrong value. how can I know the actual time between the two points.
thanks
|
|
|
|
|
If it's crucial that you have a correct timespan, you could implement your own timing mechanism through System.Threading.Timer (callback-based) or perhaps System.Timers.Timer (event-based).
There might be an even better method, I'm not sure
This space for rent!
My Blog
|
|
|
|
|
1:How to add table and columns in datagrid on button click.
2:I have two winforms one have a datagrid control and link control in it. If i click on link than a sceond form open here i have two textboxes and one comobox. Now i want to send data into the first form datagrid control.
3:Can we add new value in Comobox mean i type something in Comobox after click on button my typed value add in comobox.
Muhammad Waqas Butt
waqasb4all@yahoo.com
|
|
|
|
|
How to push data from Winforms to Crystal Report Dynamically..
How?????????
Muhammad Waqas Butt
|
|
|
|
|
What kind of data?
Have a read of these docs[^] for the most common ways of dynamically altering reporting data.
Michael
CP Blog [^]
|
|
|
|
|
Deos any body know how to convert Numbers to word mean
in text box user type: 100 it convert in One Hundard and how One Hundard in another textbox.
???????????
Muhammad Waqas Butt
waqasb4all@yahoo.com
|
|
|
|
|
|
how can i change the specific row color in a datagrid and also how can i make a row readonly in datagrid in windows forms using c#
|
|
|
|
|
You have to catch the events of Paint and Selection Changed for DataGrids. Then u can change the specific row color or making any specific row readonly.
However it will be better if u create ur own grid from scratch i.e. inheriting ur own grid control from any control.
|
|
|
|
|
Sorry but that is nonsense.
Looking at DataGridColumnStyle - especially overriding GridTextBoxColumn - is the way to go.
That has been done thousand of times here. Search the forum and/or CodeProject to find samples.
|
|
|
|
|
I am writing a c# application that save record into two table that has a relationship. But when inserting new data, the auto id suppose to be in the detail table but not. I could not figure it out. Please turn the light on. Here is the code.
================================================
static void ExPnamesAdapter_OnRowUpdate(object sender, OleDbRowUpdatedEventArgs e)
{ OleDbCommand oCmd = new OleDbCommand("SELECT @@IDENTITY", e.Command.Connection);
e.Row["ID"] = oCmd.ExecuteScalar();
e.Row.AcceptChanges();
}
private void btnSav_Click(object sender, System.EventArgs e)
{
OleDbConnection myConnection = new OleDbConnection( CONNECTION_STRING );
//// Create the DataSet
DataSet ds1 = new DataSet();
// Fill the Dataset with Names, map Default Tablename
//// "Table" to "names".
OleDbDataAdapter namesAdapter = new OleDbDataAdapter("Select LastName,FirstName,Initial,SSN,ExpungeID FROM Name",myConnection);
namesAdapter.RowUpdated += new OleDbRowUpdatedEventHandler(ExPnamesAdapter_OnRowUpdate);
OleDbCommandBuilder namesCmdBuilder = new OleDbCommandBuilder(namesAdapter);
namesAdapter.TableMappings.Add("Table","Name");
namesAdapter.Fill(ds1);
/// Fill the Dataset with Orders, map Default Tablename
/// "Table" to "detail".
OleDbDataAdapter detailAdapter = new OleDbDataAdapter("SELECT Type,ReceiveDate,ProcessDate,RejectDate,ReasonReject,PJ_ClafLet,Misc,Misc1,Misc2,Misc3,Status,ID FROM Detail",myConnection);
OleDbCommandBuilder detailCmdBuilder = new OleDbCommandBuilder(detailAdapter);
detailAdapter.TableMappings.Add("Table","Detail");
detailAdapter.Fill(ds1);
System.Data.DataRelation relCustOrd;
System.Data.DataColumn colMaster1;
System.Data.DataColumn colDetail1;
colMaster1 = ds1.Tables["Name"].Columns["ID"];
colDetail1 = ds1.Tables["Detail"].Columns["ID"];
relCustOrd = new System.Data.DataRelation("RelCustOrd",colMaster1,colDetail1);
ds1.Relations.Add(relCustOrd);
DataRow namesRow = ds1.Tables ["Name"].NewRow();
namesRow["LastName"] = this.txtlastname.Text;
namesRow["FirstName"] = this.txtfirstname.Text;
namesRow["Initial"] = this.txtInitial.Text;
ds1.Tables["Name"].Rows.Add(namesRow);
DataRow detailRow = ds1.Tables["Detail"].NewRow();
detailRow["Type"] = "A";
detailRow["Misc"] = "Testing and Working not";
detailRow["Misc1"] = "I hope this will work";
ds1.Tables["Detail"].Rows.Add(detailRow);
detailRow.SetParentRow(namesRow);
namesAdapter.Update(ds1, "Name");
detailAdapter.Update(ds1, "Detail");
myConnection.Close();
}
Mso
|
|
|
|
|
Are you kidding?
Look at this 3 lines (copied from your pasted code):
...
ds1.Tables["Detail"].Rows.Add(detailRow);
detailRow.SetParentRow(namesRow);
ds1.Tables["Detail"].Rows.Add(detailRow);
...
Last hint: One line exists twice.
|
|
|
|
|
Hi
I need a help Pls Itsvery urgent , help me to get out
I have doen a pgm to read
any schema file(.xsd) and load data's into a xml file(resultant file).
Here what I had done inside the Load button is that for any datatypes
in the schema, enter the values as james for string, 100 for interger
like that, I have specified by using the SWITCH statement. But my
requirement is such that , when I entered the .xsd file and resultant xml file then when i click the Load Button, It should create around 200 data's but, the data's should differ form each other.
I dont know how to do this. Pls help me. Here I am sending the coding
again.create a new project with c# windows application, copy this
coding and run and see.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.Xml.Schema;
namespace testdatagenerator
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtSchema;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtXml;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Data.DataSet dataSet1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.txtSchema = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.txtXml = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet1 = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
this.SuspendLayout();
//
// txtSchema
//
this.txtSchema.Location = new System.Drawing.Point(88, 24);
this.txtSchema.Name = "txtSchema";
this.txtSchema.Size = new System.Drawing.Size(440, 20);
this.txtSchema.TabIndex = 0;
this.txtSchema.Text = "";
//
// button1
//
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.Location = new System.Drawing.Point(536, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Browse";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtXml
//
this.txtXml.Location = new System.Drawing.Point(88, 64);
this.txtXml.Name = "txtXml";
this.txtXml.Size = new System.Drawing.Size(440, 20);
this.txtXml.TabIndex = 2;
this.txtXml.Text = "";
//
// button2
//
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button2.Location = new System.Drawing.Point(536, 64);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "Load";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button3.Location = new System.Drawing.Point(616, 64);
this.button3.Name = "button3";
this.button3.TabIndex = 4;
this.button3.Text = "Save";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataSet1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 120);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(776, 320);
this.dataGrid1.TabIndex = 5;
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(808, 454);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.txtXml);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtSchema);
this.Name = "Form1";
this.Text = "TestDatagenerator";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "select schema file" ;
fdlg.InitialDirectory = @"c:\CDEV\testdatagenerator" ;
fdlg.Filter = "schema files(*.xsd) |*.xsd| all files(*.*) | *.*";
fdlg.FilterIndex = 2 ;
fdlg.RestoreDirectory = true ;
if(fdlg.ShowDialog() == DialogResult.OK)
{
txtSchema.Text = fdlg.FileName ;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[i] = (string) "This is string";
break;
case "System.Int32":
oValues[i] = (int) 100;
break;
case "System.DateTime":
oValues[i] = new DateTime(2004,10,12);
break;
case "System.Decimal":
oValues[i] = new Decimal(999999999.99);
break;
case "System.Int16":
oValues[i] = (short) 32767;
break;
case "System.Int64":
oValues[i] = (long) 9223372036854775807;
break;
case "System.Double":
oValues[i] = (double) 888888888888888;
break;
}
i += 1;
}
dTbl.Rows.Add(oValues);
}
}
private void button3_Click(object sender, System.EventArgs e)
{
dataSet1.WriteXml(txtXml.Text,XmlWriteMode.WriteSchema );
MessageBox.Show("Saved");
}
}
}
|
|
|
|
|
Hi,
I have looked at the API of WM Encoder 9.0 and could able to capture the screen in the form of a video. But instead of saving to a file i want to send across the network and play it as an video file.
This can be done by WM Encoder 9.0 broadcast mechanism. But i am using another high level API for the networking. Since i cannot use the Windows Media Encoder 9.0 API for transmitting, is there any way i can get the frames of the encoding video format asynchronous (or some way) so that i can send there frames across the wire using the custom API?
Is it possible to do this using the Windows Media Format 9.0 API?
Thanks,
vinod
|
|
|
|
|
I'm writing a program that needs to capture the Fn key on my laptop, but have not been able to capture it.. I've tried using of the keyboard hooking using SetWindowsHookEx, but it doesn't capture the key stroke. Any ideas?
|
|
|
|
|