Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
AnswerRe: Diference betwteen DrawText and RichTextEdit (winforms) Pin
Henry Minute13-May-09 0:56
Henry Minute13-May-09 0:56 
QuestionDetermine device type using IP Pin
lachu00912-May-09 18:19
lachu00912-May-09 18:19 
AnswerRe: Determine device type using IP Pin
Rajdeep.NET is BACK12-May-09 18:52
Rajdeep.NET is BACK12-May-09 18:52 
AnswerRe: Determine device type using IP Pin
Fatbuddha 112-May-09 22:12
Fatbuddha 112-May-09 22:12 
AnswerRe: Determine device type using IP Pin
OriginalGriff12-May-09 23:03
mveOriginalGriff12-May-09 23:03 
QuestionTryEnter always return true in Timer Event Pin
geossl12-May-09 17:40
geossl12-May-09 17:40 
AnswerRe: TryEnter always return true in Timer Event Pin
N a v a n e e t h12-May-09 18:23
N a v a n e e t h12-May-09 18:23 
AnswerRe: TryEnter always return true in Timer Event Pin
OriginalGriff12-May-09 22:42
mveOriginalGriff12-May-09 22:42 
There are a couple of things here:
1) Please try to use the "code block" button below to enclose your samples - it preserves the formatting and make it easier to read.
public partial class Form1 : Form
    {
    private object BlockingObj = new object();
    private void timer1_Tick(object sender, EventArgs e)
        {
        bool ret = System.Threading.Monitor.TryEnter(BlockingObj, 1);
        if (ret)
            {
            try
                {
                DialogResult result = MessageBox.Show("test", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                }
            finally
                {
                System.Threading.Monitor.Exit(BlockingObj);
                }
            }
        }
    }


2) The code: TryEnter attempts to establish an exclusive lock on the object. If it suceeds, then you display a messagebox (which is application modal, so the App can do nothing else until it is dismissed) then release the lock.

Comments:
A) because you release the lock in the timer event in which you establish it, it will always succeed.
B) Why keep the result of a MessageBox if you are going to ignore it?
C) Under what circumstances do you expect MessageBox to throw an exception? By all means put the try...catch around the exclusive lock, that will catch null objects, but otherwise it just complicates your code unneccessarily.

No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.

This message is made of fully recyclable Zeros and Ones

AnswerRe: TryEnter always return true in Timer Event Pin
Nicholas Butler12-May-09 23:18
sitebuilderNicholas Butler12-May-09 23:18 
QuestionConvert From VB.Net to C # Project Pin
misCafe12-May-09 17:07
misCafe12-May-09 17:07 
AnswerRe: Convert From VB.Net to C # Project Pin
Dave Kreskowiak12-May-09 17:22
mveDave Kreskowiak12-May-09 17:22 
GeneralRe: Convert From VB.Net to C # Project Pin
misCafe12-May-09 17:35
misCafe12-May-09 17:35 
QuestionUsing richtextbox as output Pin
Quake2Player12-May-09 16:53
Quake2Player12-May-09 16:53 
AnswerRe: Using richtextbox as output Pin
Dave Kreskowiak12-May-09 17:21
mveDave Kreskowiak12-May-09 17:21 
Questioninheriting varibles from within a class Pin
antrock10112-May-09 16:03
antrock10112-May-09 16:03 
AnswerRe: inheriting varibles from within a class Pin
Luc Pattyn12-May-09 16:45
sitebuilderLuc Pattyn12-May-09 16:45 
GeneralRe: inheriting varibles from within a class Pin
antrock10112-May-09 16:55
antrock10112-May-09 16:55 
GeneralRe: inheriting varibles from within a class Pin
Luc Pattyn12-May-09 17:15
sitebuilderLuc Pattyn12-May-09 17:15 
GeneralRe: inheriting varibles from within a class Pin
antrock10112-May-09 17:17
antrock10112-May-09 17:17 
AnswerRe: inheriting varibles from within a class Pin
PIEBALDconsult12-May-09 17:20
mvePIEBALDconsult12-May-09 17:20 
GeneralRe: inheriting varibles from within a class Pin
Luc Pattyn12-May-09 17:22
sitebuilderLuc Pattyn12-May-09 17:22 
GeneralRe: inheriting varibles from within a class Pin
PIEBALDconsult12-May-09 17:41
mvePIEBALDconsult12-May-09 17:41 
GeneralRe: inheriting varibles from within a class Pin
antrock10112-May-09 17:25
antrock10112-May-09 17:25 
GeneralRe: inheriting varibles from within a class Pin
antrock10112-May-09 17:36
antrock10112-May-09 17:36 
GeneralRe: inheriting varibles from within a class Pin
PIEBALDconsult12-May-09 17:46
mvePIEBALDconsult12-May-09 17:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.