|
You can create a new class, encapsulating both values and return that. Or read up on the out-parameter.
I are troll
|
|
|
|
|
Well it should work using object[] return value from the delegate, but you may need to cast to the proper type. If your delegate it returning object, but it's actually an object[] that's been boxed, just cast the returned object to object[] like so:
public delegate object ExecuteDelegate(int i, string s);
...
object[] values = (object[])ExecuteDelegate(int i, string s);
In this case you just unbox the object[] from the return value into the propery type. Or, if your delegate is returning object[] they should be accessible right away:
public delegate object[] ExecuteDelegate(int i, string s);
...
object[] values = ExecuteDelegate(int i, string s);
It is sometimes helpful to create a class (as others have suggested) to represent the delegate's result values that have meaningful property names, etc., but it really depends on your situation. I'd say if the result data is complex or the delegate is used in multiple places to create a class for it; otherwise, just stick with object[].
Keep It Simple Stupid! (KISS)
|
|
|
|
|
You can use the out parameter modifier:
void MyCallback(int input, out string output1, out int output2);
|
|
|
|
|
how i can insert date into table in data base
the data type in table is datetime
|
|
|
|
|
|
thanks for this lesson
but my problem still is not solved
i tried to insert datetime like this
system.datetime.now.toshortdate.tostring();
but witout useful
what is the suloation
|
|
|
|
|
I think you don't have to use the ToString()-method because this will store the date as string and not as datetime.
Maybe you could provide your code, so that we can have a look at.
Regards
Sebastian
|
|
|
|
|
If you want to insert current time and you're using SQL Server, you can use GETDATE()[^] function in the SQL statement.
|
|
|
|
|
|
Celie wrote: how do I invoke the INotifyPropertyChanged interface to transfer the setting of the visibility to the corresponding user-controls on ALL forms ?
You need to have implemented the INotifyPropertyChanged interface and provided an event for PropertyChange to which your forms can subscribe to. When form A changes the property of the object all other forms should get the notification if they are subscribed to the event.
only two letters away from being an asset
|
|
|
|
|
I am not sure If I got your question correctory.
I think what you could do is, all the Forms user control will provide (implement) a handler for the PropertyChanged event from the background form's user control and they will toggle their state accordingly.
But anyway, I am wondering why you designed like this??
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Hi,
This is my first message to this forum, so sorry for any mistakes.
I have created a worker thread which is filling a dataset. The thread action is as follows:
public void fillDataSet()
{
ds.Clear();
ds.Tables.Clear();
System.Data.OracleClient.OracleDataAdapter myAdapter = new System.Data.OracleClient.OracleDataAdapter(cmd);
try
{
myAdapter.Fill(ds);
return;
}
catch (ThreadAbortException)
{
return;
}
catch (System.Data.OracleClient.OracleException oe)
{
MessageBox.Show(oe.Message, "Oracle error");
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Application error");
return;
}
}
From the main thread, by clicking a button, i'm trying to abort the worker thread:
private void buttonAdv1_Click(object sender, EventArgs e)
{
t.Abort();
while (true)
{
if (!t.IsAlive)
{
MessageBox.Show("The script was cancelled by the user", "Script cancelled");
break;
}
}
this.Close();
}
The problem is that t.Abort() waits till the end of filling a dataset. The problem is when filling dataset takes an hour, then user have to wait this hour for any effects of cancelling.
Do you have any ideas how can you cancell filling a dataset immediately?
Thanks for any responses,
Kasatch
|
|
|
|
|
From a quick bit of googling, it seems the ThreadAbortException only applies when you're working with threads directly - it's obfuscated away when you're working with the BackgroundWorker. - See this article[^]
One fix would be to use a threadpool and create the thread manually - then this design *should* work fine.
You could also try the code in the above article, since it's trying to fix this particular issue.
|
|
|
|
|
Not sure about this, but I suspect that the reason for this behaviour is because Thread.Abort cannot abort the execution if it's done by unmanaged code. It must wait until the execution is returned to managed code. So if in OracleClient the fill mechanism is created using unmanaged code, that would explain the long period of waiting (until the Fill has finished).
The only thing that comes in mind is that you limit the execution somehow. For example, could you use DbDataAdapter.Fill Method (Int32, Int32, DataTable[])
[^] and set the maximum amount of rows for the fill.
The downside is of course, that you must set this before execution and even if the fill is fast, you won't get more rows than specified. However, perhaps you could first fetch, say 100 records and then have an option for the user to fetch the rest. This way you could split the operation to smaller parts.
|
|
|
|
|
i created a new thread and dynamically created a timer, in the thread a method is called and in it registered another method that update the db, what i want to do is to fire the tick event , i wrote the
private void dbtimer_Tick(object sender, EventArgs e)
{
dbtimer.Stop();
dbtimer.Interval = 1000;
dbtimer.Stop();
}
but it didn't fire
|
|
|
|
|
Of course it didn't fire, you stopped it just after starting it
only two letters away from being an asset
|
|
|
|
|
|
have you fixed your problem?
Cause the code you posted should fire atleast once, but you have put nothing in the event handler to actual do anything noticable
|
|
|
|
|
musefan wrote: Cause the code you posted should fire atleast once,
Really?? Not from what I'm seeing. That timer has to run for at least the interval specified before it's stopped in order to do that.
|
|
|
|
|
well the code he has posted only shows him setting the interval and stopping the timer inside the event handler. there is no code to show how the timer has been setup outside of that.
Maybe I am missing something here?
|
|
|
|
|
Yeah, you are. He called stop, set the interval, and called stop again.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
He did not call it, he placed that code in the event handler. which as we know now was never assigned to the timer tick event
|
|
|
|
|
Is this a trick question?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
sorry i was offline.
tanks for all who reply for my question, it's not a trick, actually stopping the timer twice in this code a mistake, but what i wanted was to fire the timer_tick event,to do so i have to register it with systemeventhandler isn't it when doing this dynamically.
i tried it in design and found that there is a code registering the timer_tick event with systemeventhandler .
|
|
|
|
|
No, its a 'tick' question
|
|
|
|