Click here to Skip to main content
15,894,405 members
Home / Discussions / C#
   

C#

 
GeneralRe: RDP connections in tabs Pin
Mycroft Holmes13-Aug-18 13:28
professionalMycroft Holmes13-Aug-18 13:28 
QuestionClasses In Threads - Pause One Until Another Finished Pin
Kevin Marois8-Aug-18 6:43
professionalKevin Marois8-Aug-18 6:43 
AnswerRe: Classes In Threads - Pause One Until Another Finished Pin
Richard Deeming8-Aug-18 8:05
mveRichard Deeming8-Aug-18 8:05 
AnswerRe: Classes In Threads - Pause One Until Another Finished Pin
OriginalGriff8-Aug-18 8:09
mveOriginalGriff8-Aug-18 8:09 
GeneralRe: Classes In Threads - Pause One Until Another Finished Pin
Kevin Marois8-Aug-18 8:22
professionalKevin Marois8-Aug-18 8:22 
GeneralRe: Classes In Threads - Pause One Until Another Finished Pin
OriginalGriff8-Aug-18 22:08
mveOriginalGriff8-Aug-18 22:08 
GeneralRe: Classes In Threads - Pause One Until Another Finished Pin
Richard Deeming9-Aug-18 0:48
mveRichard Deeming9-Aug-18 0:48 
Questionthreads Pin
Laurent mortroux6-Aug-18 22:44
Laurent mortroux6-Aug-18 22:44 
Hello

i créate 10 threads to do a task.
i create a Semapohre to limit access at compteur by 3 threads

how to lock data (compteur)

C#
namespace threads
{
    class Program
    {

        public static int compteur;
        public static object ob = new object();
        public static SemaphoreSlim sem = new SemaphoreSlim(3);

        public static void Thread_test() {
            sem.Wait();
            for (int i = 0; i < 1000000; i++)
            {
                compteur++;
            }
            sem.Release();
            System.Console.WriteLine(compteur.ToString());
        }

        static void Main(string[] args)
        {
            Thread[] th = new Thread[10];
            for (int i = 0; i < th.Length; i++)
            {
                th[i] = new Thread(Thread_test)
                {
                    Name = "thread_" + i
                };
                th[i].Start();
            }

            System.Console.ReadLine();
        }
    }
}


Result:

thread_2 = 1264634
thread_0 = 1440996
thread_1 = 1645012
thread_3 = 2344585
thread_5 = 2694858
thread_4 = 2809001
thread_6 = 3628891
thread_8 = 3651918
thread_7 = 3991965
thread_9 = 4527904


and i want this without lock function just with Semaphore:

thread_3 = 1893992
thread_1 = 2735536
thread_4 = 4274643
thread_2 = 4349873
thread_0 = 6248051
thread_5 = 7430503
thread_6 = 8107979
thread_7 = 8937401
thread_9 = 9815069
thread_8 = 10000000


Thank you so much
AnswerRe: threads Pin
OriginalGriff6-Aug-18 23:31
mveOriginalGriff6-Aug-18 23:31 
SuggestionRe: threads Pin
Richard Deeming7-Aug-18 2:29
mveRichard Deeming7-Aug-18 2:29 
AnswerRe: threads Pin
Richard Deeming7-Aug-18 2:28
mveRichard Deeming7-Aug-18 2:28 
GeneralRe: threads Pin
Laurent mortroux7-Aug-18 3:28
Laurent mortroux7-Aug-18 3:28 
GeneralRe: threads Pin
Richard Deeming7-Aug-18 3:48
mveRichard Deeming7-Aug-18 3:48 
QuestionLG Smart TV webos 3.0 .net framework client development Pin
impeham6-Aug-18 12:05
impeham6-Aug-18 12:05 
AnswerRe: LG Smart TV webos 3.0 .net framework client development Pin
Simon_Whale7-Aug-18 4:22
Simon_Whale7-Aug-18 4:22 
QuestionHow do you color cell of the listview ? Pin
Member 24584675-Aug-18 17:51
Member 24584675-Aug-18 17:51 
AnswerRe: How do you color cell of the listview ? Pin
Mycroft Holmes5-Aug-18 19:43
professionalMycroft Holmes5-Aug-18 19:43 
AnswerRe: How do you color cell of the listview ? Pin
OriginalGriff5-Aug-18 20:27
mveOriginalGriff5-Aug-18 20:27 
GeneralRe: How do you color cell of the listview ? Pin
Member 24584678-Aug-18 15:33
Member 24584678-Aug-18 15:33 
QuestionSelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Member 138463763-Aug-18 22:32
Member 138463763-Aug-18 22:32 
AnswerRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff3-Aug-18 22:40
mveOriginalGriff3-Aug-18 22:40 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Member 138463763-Aug-18 23:11
Member 138463763-Aug-18 23:11 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff3-Aug-18 23:22
mveOriginalGriff3-Aug-18 23:22 
QuestionRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Eddy Vluggen3-Aug-18 23:41
professionalEddy Vluggen3-Aug-18 23:41 
AnswerRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff4-Aug-18 0:04
mveOriginalGriff4-Aug-18 0:04 

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.