Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
W

whizzs

@whizzs
About
Posts
18
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Problem with Mutex in multithreading Application
    W whizzs

    Try switching your Thread.Sleep(100) with your mutex.Release(). Since Thread.Sleep() is a static method you can't be sure which thread is sleeping if you have released the synchronization Also, I don't think your implementation is correct. Since your threads do not own the Mutex I do not believe they will be synchronized. You should have both threads call the same function so the Mutex can protect the resource.

    public class Test
    {
    protected Mutex mutex;
    public Test()
    {
    mutex = new Mutex(false);
    Thread A = new Thread(new ThreadStart(TF));
    Thread B = new Thread(new ThreadStart(TF));
    A.Start();
    B.Start();
    }
    void TF()
    {
    while(true)
    {
    mutex.WaitOne();
    Console.Write("do some work {0}", Thread.CurrentThread.Name);
    Thread.Sleep(100);
    mutex.ReleaseMutex();
    }
    }
    }

    and since your synchronization is inside an infinite while loop I don't know what will happen as far as sharing process time -- modified at 16:11 Tuesday 22nd November, 2005

    C# help tutorial announcement learning

  • checkedlistbox highlight and spacing
    W whizzs

    This sounds like an owner-drawn listbox, here is a good tutorial: http://www.codeproject.com/books/1930110286\_10.asp -- modified at 14:53 Friday 11th November, 2005 Basically you have to capture the draw event, measure the rectange and set its size using the measureItem event (to modify the vertical distance) To change the highlighted text you set the solidbrush color to your background color to hide the highlight. SystemColors.Highlight comes from the OS and I don't think you can change it programmatically (at least easily) Horizontal spacing is easy, just change the column width property

    C# csharp xml question

  • Dumping the DataGrid into a txt file
    W whizzs

    Is your DataGrid bound to a dataset? If so, use DataSet.WriteXML() to write the info out to an xml file. If it is bound to a DataTable, I would add the table to a DataSet and use the above command. XML files can then be opened by word or excel or whatever. If not, then you need to use foreach loops and manually write out the data.

    C# question

  • Loading Files
    W whizzs

    zaboboa wrote:

    Hello, I am loading a file within my app and the way I am refering to it is something like that: this.richTextBox1.LoadFile("c:\\tmp\\Document.rtf"); However if I want to deploy the application on some other machine, obviously the file will not be there. So, if I want to include the file in my application how do I refer to the file then? Thank you.

    Is the file something you will deploy with your code? If so you will know where it should be. You could try something like this:

    try
    {
    this.richTextBox1.LoadFile("c:\\tmp\\Document.rtf"); //of course point to where you think it is
    }
    catch
    {
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Title = "Please locate Document.rtf"; //or whatever title you want
    ofd.Filter = "RTF File|*.rft";
    ofd.ShowDialog();

    if ( ofd.FileName != "" ) { this.richTextBox1.LoadFile( ofd.FileName ); }
    else { // do something to handle the error }
    }

    C# question

  • How to check object==null for objects without Constructor?
    W whizzs

    artisticcheese wrote:

    Hello, I need to do following. If object was not initialized then assign variable to it like code below. Right now it throws an error becouse MyCert is not initialized when compared to null. How do I do what I need to do? X509ChainElement MyCert; foreach (X509ChainElement cert in chain.ChainElements) { if ( MyCert == null) { MyCert = (X509ChainElement) cert; continue; } else { .....; } }

    The quickest way is to initialize your object at the beginning. I am assuming you will be doing some processing between your declaration and your foreach loop, otherwise it makes no sense to check for a null because you know it is uninitialized. So it would look like this: X509ChainElement MyCert = null; // do some processing and other things..... foreach (X509ChainElement cert in chain.ChainElements) { if ( MyCert == null) //has not been initialized somewhere before the loop { MyCert = (X509ChainElement) cert; continue; } else { .....; } } But what I don't understand about your code is that only the first element will ever be assigned to MyCert. Of course I only get to see a small snippet and this may be the functionality you want.

    C# question help tutorial

  • How to Retrieve Serial Ports and Parallel Ports in the current system by Using Visual C#
    W whizzs

    Here's one: http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx Or you can get the .NET framework 2.0 (beta) and use the System.IO.Ports namespace which has everything you need bundled in one managed assembly

    C# csharp json tutorial

  • Regex.Replace hangs !!!
    W whizzs

    my reg ex string did not post correctly it should be @"(?:\[quote\])(?.*)(?:\[/quote\])"

    C# regex help question

  • Regex.Replace hangs !!!
    W whizzs

    Not it is a big deal, but I would clean the code up a bit by using non-capturing groups for the [quote] and [/quote] because you just want to see if they are there, but don't need them. So the regex string would be: @"(?:\[quote\])(?.*)(?:\[/quote\])" if ( m.success ) { return "####"+m.Groups["quo_text"].Value+"###"; } then I would change the if statement to a while loop in case the user has more than 1 quote block in a line string [] s = new string[]; int i = 0; while ( m.success ) { s [i] = "####"+m.Groups["quo_text"].Value+"###"; m.NextMatch(); } return s; But please send an example of the string that causes it to hang

    C# regex help question

  • Setting dynamic Text Box after post backs
    W whizzs

    Are you having trouble checking the value? If so, use the RangeValidator class, you can set the control for it to validate, maximum value and minimum value. If the value of the text box is outside the range, you can set the value of the text box to the minimum. I would do this in the page_load section in an if block "if (Page.IsPostBack)" ex if ( Page.IsPostBack ) { rangevalidator.ControlToValidate = "textbox1"; rangevalidator.MaximumValue = "100"; rangevalidator.MinimumValue = "15"; if ( rangevalidator.IsValid ) { // do your thing } else { textbox1.Text = "15"; rangevalidator.ErrorMessage = "whatever you want to tell the user"; } }

    C# css

  • c# and mysql
    W whizzs

    use the dataAdapter class and the setup wizards provided in visual studio. If you are not familiar with ADO.NET, I suggest you google mysql and C# and look for some tutorials.

    C# question csharp database mysql

  • Creating a database in C#
    W whizzs

    If it was me, I would use MySQL instead of a text file. It is free and open source (not that you would make changes to the underlying database engine) and there are plenty of administrative tools that are easy to use. Load the engine, create your tables and go. On the C# side just create a dataset that reflects your database, populate the dataset at runtime, bind your dataset to your webform or windows form and enjoy the hours the microsoft people put in to make your life easy. As far as references, I went to half price books and got an ADO.NET book, that is your best bet.

    C# csharp database help learning

  • How can i change Windows Form in real time
    W whizzs

    If you are changing the parent form then use: this.Size = new Size ( width, height ); if you are opening a new window then: Form form2 = new Form(); form2.Size = new Size(300,300);

    C# question

  • Enums and Ints
    W whizzs

    In C# use the Enum static method ToObject Suit myCard = (Suit) Enum.ToObject ( typeof ( Suit ), 12 ); This will set myCard to an ace (substitute the 12 for your integer you want the enum to be). Hope that helps

    C# tutorial question lounge

  • Enums and Ints
    W whizzs

    Whew, where to begin. First about the enums. I am assuming your Card class set method is structured as such: Card.Set ( Rank r, Suit s) and you have an array of Cards in deck[]. So to set your first card you would say deck[0].Set ( Rank.Hearts, Suit.Ace ). Now the first problem is you have Rank and Suit mixed up, the Suit should be hearts, clubs, etc. Confusing to read. Your second issue is your Card property Rank and Suit have the same name as your enum, that cannot be. I see what you are doing, you want to return that enum to set the next card with it, but you can't have the same name. I would change the name to CardRank and CardSuit and define the property like this: //member variables private Rank cardRank; private Suit cardSuit; //Properties public Rank CardRank { set { cardRank = value; } get { return cardRank; } } // do the same for CardSuit now your swap functions will be: tempCard.Set ( deck[first].CardRank, deck[first].CardSuit ); If you used integers in you Set function prototype then this won't work and you have to modify your properties to convert to integer or from integer depending on what your members are. Your third issue is your last card will never get shuffled, Random returns a number less than the number passed in and your first and second could theoretcially be the same card (not a real problem, just wasted a shuffle) If you want the integer value of an enum do this: int x = (int) Rank.Clubs; //now x = 4 or Rank r = Rank.Clubs; int x = (int) r; //x = 4 finally if you want the string value: string s = Rank.Clubs.ToString(); // s = "Clubs"

    C# tutorial question lounge

  • Foreign key
    W whizzs

    Typically they are used for inner joins to prevent cartesian products

    C# database question

  • use a file stream just in memory
    W whizzs

    Have you tried the MemoryStream class is System.IO?

    C# question performance

  • Beginner Help: Unassigned local variable
    W whizzs

    Your problem is that it is possible in your if statement to never assign a value to finalSalary since you declared finalSalary at the beginning and did not initialize it. So if someone enters a "4" at your prompt the code will execute the final "else" statement and write out to the console "That is not a valid entry" but will continue on to the final Console.WriteLine which will try to execute with an uninitialized variable. Visual studio is smart enough to detect when people try to initialize variables inside of "if" statements but not smart enough to know if all paths assign a valid result to the variable so it always throws a flag when you try to do this. The answer is to do one of the following: 1) initialize the variable at instantiation 2) move the Console.WriteLine statement to inside each "if" clause that you want it to print the final salary (probably your best bet since you don't want it to write out if the users response is invalid) Hope this helps

    C# help csharp css question career

  • Check valid XML element name.
    W whizzs

    I'm not sure about a validate function, but you could do it this way: using System.Text.RegularExpressions; . . . // reg ex to validate an XML element name Regex reg = new Regex ( @"^(?!xml)[a-zA-Z]\w+$", RegexOptions.IgnoreCase ); if ( reg.IsMatch ( "STRING TO CHECK" ) ) { // do something with it } I did not verify the regular expression string against all possible errors (malformed element names), but you should be able to correct any mistakes or add characters that you want to be valid. I don't like to use anything other than what is already there. Hope this helps

    C# xml tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups