|
Hi Folks, I wonder if somebody can either point me in the right direction or explain a certain concept to me... i just can't figure it out (i've browssed through MSDN)...If in an application I have several threads running and while these threads are running something arrives on the serial port of the computer...Using a control I can raise an event to signal this "BUT" will the application be aware that this event has taken place? Or how can I make sure that the application is aware that something has been recieved at the serial port while other threads are running?.... Please can someone help...
A secondary issue also related ... say again multiple threads are running in an application, in one thread I implement a lock on a certain portion of code (so this must complete execution before any other thread can resume control)... if a timer raises an event (or is due to raise an event) while another thread is executing a portion of locked code... will this timer event be lost by the time the locked code in the other thread completes???
can anyone help!!! I'm desperate... can't find this information anywhere...
Maria (phillips_maria@hotmail.com)
|
|
|
|
|
maria_p wrote:
say again multiple threads are running in an application, in one thread I implement a lock on a certain portion of code (so this must complete execution before any other thread can resume control)...
Now, what I remember from my concurrency lectures (8 to 10 years ago) if you lock a piece of code (the "critical section") other code in other threads can still execute as they are not preventing from executing, they just can't execute the locked code.
Think of the critical section as the centre of a highway intersection with an American 4-way Stop sign. (In America the rule is the first to arrive has right of way and can pass through the intersection). So the first car arrives and is allowed onto the intersection. A fraction of a second later another car arrives from a different direction, it must wait until the first car has passed through. This is locking. Now, just because some traffic has to wait to gain access to this intersection doesn't stop the traffic flowing on an interstate a mile away.
Does this help you understand how concurrency (multithreading) works?
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Yes thank you Sir, what you have said and the way you put it has given me a totally different way of looking at the issue (Excellent analogy!)... still a little confused about one issue though.... regarding the event at the serial port....
If various threads are executing in the application will the system get a chance to acknowledge the/an event (which I am expecting at some point) that may take place due to something arriving at the serial port? Or when one thread looses control another thread will immediately take control and due to this the possible event will be missed or seriously delayed? Is there a way around this or am I just missing the point about something?
If you could also explain this I'd be most grateful.
maria
|
|
|
|
|
Colin Angus Mackay wrote:
Now, what I remember from my concurrency lectures (8 to 10 years ago) if you lock a piece of code (the "critical section") other code in other threads can still execute as they are not preventing from executing, they just can't execute the locked code.
This depends on a number of factors. First, it depends on what you're locking against (if using the lock keyword). As I explained to her before, if you want to lock a block of code for all threads, then a static object (say, the Type of the class that contains the definition) should be used. If she uses an instance variable (such as this ), then only the method will be locked for that instance no matter how many threads reference the class.
If you use the lock keyword, a Monitor is used which does block successive calls by different threads. The only way for threads to not wait is to use Monitor.TryEnter or use a Mutex and call WaitOne with a value to set the timeout.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Don't forget about all the articles in the .NET Framework SDK besides those in the class library. There is a pretty big selection of articles about threading in .NET at http://msdn.microsoft.com/library/en-us/cpguide/html/cpconthreading.asp[^] which also includes a lot of examples. Many of the overviews should even discuss threading in general for those not familiar with threads.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'v been converting some classes I wrote in VB.net to stick them in a C# DLL, but have come accross some wierd irregularities in the .net architecture.
Firstly, the C# compiler will not allow me to explicity pass the value of one numerical variable into an enumerated data type, whereas VB allowed it, and MSDN swears blind it should. For instance:
VB: mnFog(x, y) = Convert.ToByte(sChar) - works fine
C#: mcFog[nLocX, nLocY] = Convert.ToByte(sChar); - Cannot implicitly convert type 'byte' to 'ThisEnum'
The enum in question is derived from a byte.
Secondly, C# just doesnt "see" some methods and properties which VB can use. For instance, in Microsoft.Data.Odbc the OdbcDataReader has an Item collection which allows its user to retrieve a field by its SQL name, instead of its column number (like the .Get[Type]() functions).
See for yourself, reference the DLL, find "Microsoft.Data.Odbc.OdbcDataReader.Item" in the object browser, then try and use it.
Has anyone else experienced these sort of problems?
|
|
|
|
|
dalm wrote:
Cannot implicitly convert type 'byte' to 'ThisEnum'
Cast your value you pass, so if you have a function sig. which has an enum as a parameter such as this:
int SomeFunc(ThisEnum e);
and you know the enum value, simply cast it when you make the method call:
int a = 2;
SomeFunc((ThisEnum)a);
dalm wrote:
Secondly, C# just doesnt "see" some methods and properties which VB can use. For instance, in Microsoft.Data.Odbc the OdbcDataReader has an Item collection which allows its user to retrieve a field by its SQL name, instead of its column number (like the .Get[Type]() functions).
C# doesn't syntactically reference items like VB.NET does, it uses the [] syntax instead.
- Nick Parker My Blog
|
|
|
|
|
Hi,
I'm desperate: I cannot eliminate that fastidious flicker that occurs when a panel is redrawn (it has to been redrawn every 150ms so it's not a CPU issue).
I've tried with
this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);<br /> after the "InitializeComponent();" call, but it doesn't help.
Then I tried doing all drawing operations on a Bitmap, and at the end draw the Bitmap on the form: no relevant effects. (a sort of manual doubleBuffer)
the source code can be found at this URL:
http://utenti.lycos.it/yuppygames/codeproject/flicker.zip
Please, can you check my code or suggest another method?
thank you
|
|
|
|
|
Drawing the bitmap directly on to your form instead of using a Panel will help.
Get rid of panel1 completely and move the drawing code to an override of Form1. Try
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
e.Graphics.DrawImage( //draw shade shade
barran,
new Rectangle(160, 4, 299, 32), // destination rectangle
0.0f, // source rectangle x
0.0f, // source rectangle y
299, // source rectangle width
32, // source rectangle height
GraphicsUnit.Pixel,
imageAtt);
e.Graphics.DrawImageUnscaled(temp2,new Rectangle(160+xtitolo,7,287,27)); //draw title
}
Then in timertitolo_Tick method Invalidate() the form rather than panel1
|
|
|
|
|
thank you very much.
I did what you said and now it works.
I can't believe it was panel's fault!
I created that panel because I wanted to avoid repainting every single pixel of the form thinking it was faster
if anyone wants to see the correct code, click here:
http://utenti.lycos.it/yuppygames/codeproject/flicker2.zip
thank you again colderthanfusion
|
|
|
|
|
Hi everybody:
I'm doing my first application in .NET.
I know how use in my application the Visual Xp Styles.
//before running in main form.
Application.EnableVisualStyles()
But, is not exactly that I want. I only want get, at runtime, the name ( or any other ID ) of the current actived Theme from OS Windows, and (if is XP) current actived Visual Style.
Can anybody help me?
Advanced Thanks.
Best Regards.
|
|
|
|
|
look out for WMI. It's in the Namespace System.Management
scio me nihil scire
My OpenSource(zlib/libpng License) Engine:
http://sourceforge.net/projects/rendertech
Its incurable, its a Pentium division failure.
|
|
|
|
|
Try poking around in the Visual Styles Reference[^] of MSDN. You will want to look at OpenThemeData() and various other functions depending on what you are looking for.
- Nick Parker My Blog
|
|
|
|
|
P/Invoke GetCurrentThemeName from the uxtheme.dll library:
[DllImport("uxtheme.dll", CharSet=CharSet.Unicode)]
private static extern void GetCurrentThemeName(
out string themeFileName,
int maxFileNameChars,
out string colorSchemeName,
int maxSchemaNameChars,
out string sizeName,
int maxSizeChars); You should only call this if theming is supported, otherwise an exception will be thrown (since uxtheme.dll won't be found on older systems). You can do this like so:
Version v = OSFeature.GetVersionPresent(OSFeature.Feature.Themes);
if (v != null)
{
} You should also P/Invoke IsThemeActive to see if the theming is even active for the current OS:
[DllImport("uxtheme.dll")]
private static extern bool IsThemeActive(); Again, only call this if theming is supported by the OS.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello,
I have a .aspx.cs file and a group of .cs files I need to compile together. When I try this on Visual Studio .NET, there are no compile issues, but when I try to execute the file, it comes across a literal form control ("error_tags") and gives error "type or namespace cannot be found".
The class in the .aspx.cs files inherits from a base class in the .cs file. The base class contains the definition "public Literal error_tags;" Is the issue that the .cs files are not being compiled?
Previously, when I was compiling my .dlls from the command line and moving them to the bin folder I had no issues.
Any ideas?
Thanks.
|
|
|
|
|
Is the .aspx referencing the right class in the code behind ?
The 'Page' directive should have the 'Inherits' attribute:
Inherits="YourNameSpace.YourClass"
|
|
|
|
|
Yes, the .aspx reference is fine - like I said, things were working fine when compiling from the command line. It has to do (I believe) with compiling in Visual Studio .NET.
|
|
|
|
|
The <%@ Page%> should inherit from the class defined in the .aspx.cs file, as well as contain the name of the assembly in which that class is contained. If the class in that file inherits from another class defined in another .cs file, that latter class should derive from System.Web.UI.Page .
If you right-click on the files, select Properties, and examine the "Build Action" property, these should say "Compile". This is the default build action for .cs files. If the project compiles all the files set for compilation and there are no build problems, then all your Types are being resolved correctly. The only problem would be that the Inherits attribute of the <%@ Page%> declaration probably isn't referencing the right Type, and / or the CodeBehind attribute does not specify the path to the correct .aspx.cs file.
Finally, make sure that the Liberal error_tags class is declared as public , protected (recommended), internal , or protected internal . If it is declared as private no class - including subclasses - can access it without using reflection (which is expensive and not a very good design).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'v never used XML before today, and I have a small query. With Microsofts XML namespaces, is it be possible to pass variables taken from a serialised object through (set) property procedures?
|
|
|
|
|
dalm wrote:
With Microsofts XML namespaces, is it be possible to pass variables taken from a serialised object through (set) property procedures?
What exactly do you mean? If you're using the XML Serialization classes from System.Xml.Serialization , then public properties are serialized by default (you can control this with the attributes like XmlElementAttribute and XmlAttributeAttribute . When deserializing, the values are assigned to the properties again via the set accessor so any code you have in the set accessors will be run.
For more information - including examples - on XML Serialization, see http://msdn.microsoft.com/library/en-us/cpguide/html/cpconintroducingxmlserialization.asp[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
When I use a manifest file to enable windows xp themes the calendar control get seriously screwed up. When a range is selected the painting isn't done properly. Has anyone ran into this before? Any solutions to this?
|
|
|
|
|
Is it possible to make ANY string "clickable", just like http:// links can be clicked (if you turn on detect URLS), in a richtextbox? Or maybe make an icon, picture or other objects "clickable"?
/Fredrik
|
|
|
|
|
I think you have to write yout custom richtextbbox control or use axBrowser control.
Mazy
No sig. available now.
|
|
|
|
|
Just add a handler to the LinkClicked event, something such as the following will work:
RichTextBox input;
input.LinkClicked += new LinkClickedEventHandler(Link_Clicked);
protected void Link_Clicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
- Nick Parker My Blog
|
|
|
|
|
But this only works for URLs, I want it to work for ANY type of string..
Fredrik
|
|
|
|