473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

c# as a replacement for a script language

Hi there,
i'm evaluating if c# is suited to replace a script language. Most of
the elements of this language can be replaced with a c#-library, but
it also has some realtime-like elements. E.g., in this language, the
following code is possible:

{
Int32 i=0;
OnEvent ( ... )
{
Print (i);
}
}

Whenever a certain event occurs, the specified code is executed in a
seperate thread (something similar exists in pearl (not perl) or other
realtime languages).
Of course this can be achieved with c#, but the user (which is used to
the old script language) should be able to write c#-code which looks
nearly the same as the example above.
Does anybody have an idea how this can be done?

Bye,
Ingo
Nov 15 '05 #1
2 1569
Can someone tell me what replacing only the method name "Invoke" with "BeginInvoke" in the example below means? They both produce the same results. However, when I threw some volume at it the Invoke seemed to perform more stably, although the BeginInvoke seemed faster. Is it because the BeginInvoke has a bit more overhead associated with it?

-----------------------------------------------------------

When you receive an asynchronous callback, it is recommended
that you always update the control from the same thread in which
the control was created because windows forms controls are _not_ threadsafe.

Typically, if you are updating controls from asynchronous callback methods
that are not executing in the same thread in which the control was created,
use Control.Invoke() passing the delegate that updates the control.

You can aso use Control.InvokeRequired to check if the thread is
the same thread in which your control was created, and then accordingly
decide whether you need to call Control.Invoke().

Some C# code shown below (same semantics apply to VB.NET):

if( ! MyControl.InvokeRequired )
{
this.AddItemToControl( item );
else
{
MyControl.Invoke( new AddItemDelegate

( this.AddItemToControl, new Object[] {item} ));
}



Nov 15 '05 #2
100

"Empire City" <a@b.com> wrote in message news:UM*********************@twister.nyc.rr.com...
Can someone tell me what replacing only the method name "Invoke" with "BeginInvoke" in the example below means? They both produce the same results. However, when I threw some volume at it the Invoke seemed to perform more stably, although the BeginInvoke seemed faster. Is it because the BeginInvoke has a bit more overhead associated with it?

When you call Invoke the caller will be blocked until the callee returns (maybe that is the reason you find it more stably) If you call BeginInvoke, though, the caller (worker thread )won't be blocked and will continue working and maybe that's why you find it faster.

The Invoke make sense only when it is called from outside the UI thread, owning the control (when InvokeRequired is true) and doesn't make sense otherwise. BeginIvoke is very useful when is called from inside the UI thread as well. In this case the delegate you provided will be the next thing to be executed when the current method ends. You can think of it for something like PostMessage in Windows.
HTH
B\rgds
100
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Erik Johnson | last post by:
This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. I've hacked a bit in Python, and generally think it is a rather...
13
by: Dave Boland | last post by:
The other day I was asked if there is an open source replacement for VB6 that is cross-platform. I spent a little bit of time at Barnes-Noble and looking at news groups, but don't have a good...
1
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one...
5
by: Tom Berry | last post by:
We currently are trying our first transformation from VB6 to VB.Net. Of course, the Printer object is gone, but I'm having trouble finding the replacement syntax necessary to perform similar...
3
by: Wolfgang Keller | last post by:
Hello, this is a potentially veeery dumb question, but: - If an application supports VBA as a macro language, - and if you can execute Python code from within a VBA script (how?) - and if the...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
2
by: medaps | last post by:
Hi, How do I save multi lines to a mysql memo field replacing char 13 char 10 to '\r\n' instead ?. Example the memo is saved as 'string1<13><10>string2' instead of 'string1\r\nstring2' The...
4
by: Phil Sandler | last post by:
Hello, What is the fastest/most efficient way of doing string replacement in csharp/.net? An example would be: "Hello, my name is {FirstName}, and I live in the town of {City} with my wife...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.