|
Ok inseatd of adding sql statements to a FbBatchExecution I just executed each statement using a command it looks ugly, but it works
<br />
foreach (string cmd in script.Results)<br />
{<br />
fbCommand.CommandText = cmd;<br />
fbCommand.ExecuteNonQuery();<br />
}<br />
drinking beer is fun
|
|
|
|
|
Hi,
I have created a windows form the contains a button and a list box. When the button is clicked it fires the following code,
<br />
Migration.Begin();<br />
thread = new Thread(new ThreadStart(Migration.Begin));<br />
thread.Start();<br />
Migration is a seperate class that is executed on a new thread as it will be a labour intensive task and I want the UI to remain usable.
However within the migration module I want to be able to call back to the thread that created the UI and have it append a message to the listbox.
So intially in the UI class I added a delgate which called a seperate function to add a line to the listbox:
<br />
public static LoggerListDelegate loggerListDelegate; <br />
<br />
public Logger()<br />
{<br />
InitializeComponent();<br />
loggerListDelegate = new LoggerListDelegate(AddLine);<br />
}<br />
And the function addline was as follows:
<br />
public void AddLine(string line)<br />
{<br />
lstLogger.Items.Add(DateTime.Now.ToLongTimeString() + ": " + line); <br />
}<br />
I then called this from the Migration using the following:
<br />
Logger.loggerListDelegate.BeginInvoke("******Migration has begun******",null,null);<br />
This however is giving me an issue that it is not thread safe as I am trying to invoke on different thread the list was created on.
So my understanding is that I would really need to call the Listbox invoke method, e.g.
lstLogger.Invoke(delegate, objects)
If that's correct how do I access the lstLogger from my Migration class in order to invoke it?
If this is not right how do I go about making it threadsafe?
Many many many thanks
Paul
|
|
|
|
|
There is a huge difference between Control.BeginInvoke and Delegate.BeginInvoke: Delegate.BeginInvoke will call the method on a thread from the ThreadPool, but Control.BeginInvoke will call the method on the thread that runs the message loop for that control (which usually is the main thread). Since the main thread created the form and the controls on it, it is the only thread allowed to access the controls. So you have to use Control.BeginInvoke (lstLogger.BeginInvoke or this.BeginInvoke if "this" is a form).
|
|
|
|
|
Hey Daniel,
thanks for a great response, that makes it a lot clearer for me, I was having major mental block!
I have just one further question, what is the best way for me to access the lstLogger control from a seperate class? I tried changing the control to public static but the obviously is incorrect.
I could in the migration class create a new instance of the Logger class and call it-
Logger log = new Logger();
log.lstLogger.BeginInvoke(delegate, objects)
But that won't work properly, what are you thoughts?
Thanks again
Paul
|
|
|
|
|
Can anyone still answer this?
|
|
|
|
|
Hi
I would do the following:
let's say you have 2 classes the worker class Worker and the Main Form frmMain
public class Worker
{
public event EventHandler MyInterThreadEvent;
public Worker()
{
}
protected virtual void onMyInterThreadEvent(EventArgs e)
{
if (MyInterThreadEvent != null)
{
MyInterThreadEvent(this, e);
}
}
public void ThreadMethod()
{
do
{
onMyInterThreadEvent(EventArgs.Empty);
}while(something);
}
}
public class frmMain:Form
{
private Worker MyPersonalSlave;
public frmMain()
{
InitializeComponent();
MyPersonalSlave = new Worker();
MyPersonalSlave.MyInterThreadEvent += new EventHandler(MyPersonalSlave_MyInterThreadEvent);
}
private void MyPersonalSlave_MyInterThreadEvent(object sender, EventArgs e)
{
if (!InvokeRequired)
{
}
else
{
Invoke(new EventHandler(MyPersonalSlave_MyInterThreadEvent),new object[]{sender,e});
}
}
}
Greets
m@u
|
|
|
|
|
HI,
l like to know how can i use the xp icons
from where do i get them
THANKS
Have Fun
Never forget it
|
|
|
|
|
You can get the Microsoft Common Icons here[^].
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
THANKS
but is'nt there a way to get out of the the system (XP)?
i cant find them with SEARCH
-- modified at 11:11 Friday 2nd November, 2007
Like getting out of shell32.dll???
Have Fun
Never forget it
|
|
|
|
|
I have a treeview where I add nodes. Before I add a new node to the treeview I want to check if a node with the same name allready exist, how can I do that in an easy way ?
KRR
|
|
|
|
|
<br />
if (!treeview1.Nodes.Contains(nodetoadd))<br />
{<br />
}<br />
else<br />
{<br />
}<br />
|
|
|
|
|
That would not work, consider
<br />
TreeNode tn1 = new TreeNode("item1");<br />
TreeNode tn2 = new TreeNode("item1");<br />
treeView1.Nodes.Add(tn1);<br />
if(!treeView1.Nodes.Contains(tn2)){<br />
treeView1.Nodes.Add(tn2);<br />
}else{<br />
}<br />
treenode tn2 has the text as tn1, but it is not THE same treenode.
but you could use the Name property and ContainsKey method
<br />
TreeNode tn1 = new TreeNode("item1");<br />
tn1.Name = "item1";<br />
<br />
TreeNode tn2 = new TreeNode("item1");<br />
tn2.Name ="item1";<br />
treeView1.Nodes.Add(tn1);<br />
<br />
if(!treeView1.Nodes.ContainsKey(tn2.Name )){<br />
treeView1.Nodes.Add(tn2);<br />
}else{<br />
MessageBox.Show("node exists"); <br />
}<br />
<br />
If it' stuck, DO NOT pull harder!
|
|
|
|
|
Thanks.
The last example was just the one I was looking for. It works great !
KRR
|
|
|
|
|
Is it possible to use two or more kinds of format for String.Format()?
For example, If I want to display the 1.452677e-12 as 1.45e-12, how to do?
thanks
|
|
|
|
|
Sure, why not... There are many ways to do that.
simplest way...
string result = String.Format();
result = String.Format();
depending on the formatting you are doing, you could also do
.ToString().ToString() and use the standard IFormatProviders.
Hogan
|
|
|
|
|
Hi,
can Any one tell me how to convert mm/dd/yy to dd/mm/yy format.....
Arif patel
|
|
|
|
|
Arif patel wrote: can Any one tell me how to convert mm/dd/yy to dd/mm/yy format.....
Sure, use .ToString("dd/mm/yy"); .
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi pete,
I have wrote like this
Label2.Text=DateTime.Now.ToString("dd/mm/yy");
But i am getting like this 02/27/07 which is wrong...plz reply me..
Arif patel
|
|
|
|
|
Sorry - The mm should be MM. So this would be Label2.Text=DateTime.Now.ToString("dd/MM/yy");
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi Dude its working.
Thank you.....
Arif patel
|
|
|
|
|
No, always use ISO 8601 compliant formats like "yyyy-MM-dd".
|
|
|
|
|
hello all...
An application built on C#.net2.0,i m running this application Windows Server 2003 Enterprise Edition with Sp2..The Application some Times Stops responding
and disappears(Close) during running..can any one plz tel me actual solution or cause of this problem..!
an urgent reply will be appreciated..
zshan
-- modified at 7:38 Friday 2nd November, 2007
|
|
|
|
|
Don't expect solutions without clear explanation of the situation and the error.
What DB do you use?
How do you access the DB?
How many users ?
Do you handle and log exceptions?
|
|
|
|
|
well every line of code is in try and catch block,the application was running fine before updating the windows server 2003,but after updating the windows it's creating problems like hang and gets close during running..before throwing any exception or with out writing any thing in the logs..!!!!
|
|
|
|
|
Maybe you should use profiler and look at performance counters, locks.
Make sure that you have the latest service packs installed.
|
|
|
|