Skip to content

Commit 223fe00

Browse files
pkulikovRon Petrusha
authored andcommitted
Removed duplicate topics about passing data to threads (#6416)
1 parent ea82aac commit 223fe00

File tree

12 files changed

+28
-245
lines changed

12 files changed

+28
-245
lines changed

.openpublishing.redirection.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,14 @@
13421342
"source_path":"docs/visual-basic/programming-guide/concepts/threading/walkthrough-multithreading-with-the-backgroundworker-component.md",
13431343
"redirect_url":"/dotnet/api/system.componentmodel.backgroundworker"
13441344
},
1345+
{
1346+
"source_path":"docs/csharp/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md",
1347+
"redirect_url":"/dotnet/standard/threading/creating-threads-and-passing-data-at-start-time"
1348+
},
1349+
{
1350+
"source_path":"docs/visual-basic/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md",
1351+
"redirect_url":"/dotnet/standard/threading/creating-threads-and-passing-data-at-start-time"
1352+
},
13451353
{
13461354
"source_path":"docs/fsharp/language-reference/primitive-types.md",
13471355
"redirect_url":"/dotnet/fsharp/language-reference/basic-types",

docs/csharp/programming-guide/concepts/threading/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Threading enables your C# program to perform concurrent processing so that you c
3232
|Title|Description|
3333
|-----------|-----------------|
3434
|[Multithreaded Applications (C#)](../../../../csharp/programming-guide/concepts/threading/multithreaded-applications.md)|Describes how to create and use threads.|
35-
|[Parameters and Return Values for Multithreaded Procedures (C#)](../../../../csharp/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md)|Describes how to pass and return parameters with multithreaded applications.|
3635
|[Thread Synchronization (C#)](../../../../csharp/programming-guide/concepts/threading/thread-synchronization.md)|Describes how to control the interactions of threads.|
3736
|[Thread Pooling (C#)](../../../../csharp/programming-guide/concepts/threading/thread-pooling.md)|Describes how to use a pool of worker threads that are managed by the system.|
3837
|[How to: Use a Thread Pool (C#)](../../../../csharp/programming-guide/concepts/threading/how-to-use-a-thread-pool.md)|Demonstrates synchronized use of multiple threads in the thread pool.|

docs/csharp/programming-guide/concepts/threading/multithreaded-applications.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,4 @@ newThread.Abort();
7070
## See Also
7171
<xref:System.Threading.Thread>
7272
[Thread Synchronization (C#)](../../../../csharp/programming-guide/concepts/threading/thread-synchronization.md)
73-
[Parameters and Return Values for Multithreaded Procedures (C#)](../../../../csharp/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md)
7473
[Threading (C#)](../../../../csharp/programming-guide/concepts/threading/index.md)

docs/csharp/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

docs/csharp/programming-guide/concepts/threading/thread-pooling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ private void AnotherLongTask(Object state)
4444
One advantage of thread pooling is that you can pass arguments in a state object to the task procedure. If the procedure you are calling requires more than one argument, you can cast a structure or an instance of a class into an `Object` data type.
4545

4646
## Thread Pool Parameters and Return Values
47-
Returning values from a thread-pool thread is not straightforward. The standard way of returning values from a function call is not allowed because `Sub` procedures are the only type of procedure that can be queued to a thread pool. One way you can provide parameters and return values is by wrapping the parameters, return values, and methods in a wrapper class as described in [Parameters and Return Values for Multithreaded Procedures (C#)](../../../../csharp/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md).
47+
Returning values from a thread-pool thread is not straightforward. The standard way of returning values from a function call is not allowed because `void` procedures are the only type of procedure that can be queued to a thread pool. One way you can provide parameters and return values is by wrapping the parameters, return values, and methods in a wrapper class as described in [Creating threads and passing data at start time](../../../../standard/threading/creating-threads-and-passing-data-at-start-time.md).
4848

49-
An easier way to provide parameters and return values is by using the optional `ByVal` state object variable of the <xref:System.Threading.ThreadPool.QueueUserWorkItem%2A> method. If you use this variable to pass a reference to an instance of a class, the members of the instance can be modified by the thread-pool thread and used as return values.
49+
An easier way to provide parameters and return values is by using the optional `state` object argument of the <xref:System.Threading.ThreadPool.QueueUserWorkItem%2A> method. If you use this argument to pass a reference to an instance of a class, the members of the instance can be modified by the thread-pool thread and used as return values.
5050

5151
At first it may not be obvious that you can modify an object referred to by a variable that is passed by value. You can do this because only the object reference is passed by value. When you make changes to members of the object referred to by the object reference, the changes apply to the actual class instance.
5252

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# [Threading](index.md)
22
## [Multithreaded Applications](multithreaded-applications.md)
3-
## [Parameters and Return Values for Multithreaded Procedures](parameters-and-return-values-for-multithreaded-procedures.md)
43
## [Thread Synchronization](thread-synchronization.md)
54
## [Thread Pooling](thread-pooling.md)
65
### [How to: Use a Thread Pool](how-to-use-a-thread-pool.md)

docs/standard/threading/creating-threads-and-passing-data-at-start-time.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,50 @@ ms.assetid: 52b32222-e185-4f42-91a7-eaca65c0ab6d
1414
author: "rpetrusha"
1515
ms.author: "ronpet"
1616
---
17-
# Creating Threads and Passing Data at Start Time
17+
# Creating threads and passing data at start time
18+
1819
When an operating-system process is created, the operating system injects a thread to execute code in that process, including any original application domain. From that point on, application domains can be created and destroyed without any operating system threads necessarily being created or destroyed. If the code being executed is managed code, then a <xref:System.Threading.Thread> object for the thread executing in the current application domain can be obtained by retrieving the static <xref:System.Threading.Thread.CurrentThread%2A> property of type <xref:System.Threading.Thread>. This topic describes thread creation and discusses alternatives for passing data to the thread procedure.
1920

20-
## Creating a Thread
21+
## Creating a thread
22+
2123
Creating a new <xref:System.Threading.Thread> object creates a new managed thread. The <xref:System.Threading.Thread> class has constructors that take a <xref:System.Threading.ThreadStart> delegate or a <xref:System.Threading.ParameterizedThreadStart> delegate; the delegate wraps the method that is invoked by the new thread when you call the <xref:System.Threading.Thread.Start%2A> method. Calling <xref:System.Threading.Thread.Start%2A> more than once causes a <xref:System.Threading.ThreadStateException> to be thrown.
2224

2325
The <xref:System.Threading.Thread.Start%2A> method returns immediately, often before the new thread has actually started. You can use the <xref:System.Threading.Thread.ThreadState%2A> and <xref:System.Threading.Thread.IsAlive%2A> properties to determine the state of the thread at any one moment, but these properties should never be used for synchronizing the activities of threads.
2426

2527
> [!NOTE]
26-
> Once a thread is started, it is not necessary to retain a reference to the <xref:System.Threading.Thread> object. The thread continues to execute until the thread procedure ends.
28+
> Once a thread is started, it is not necessary to retain a reference to the <xref:System.Threading.Thread> object. The thread continues to execute until the thread procedure ends.
2729
2830
The following code example creates two new threads to call instance and static methods on another object.
2931

3032
[!code-cpp[System.Threading.ThreadStart2#2](../../../samples/snippets/cpp/VS_Snippets_CLR_System/system.Threading.ThreadStart2/CPP/source2.cpp#2)]
3133
[!code-csharp[System.Threading.ThreadStart2#2](../../../samples/snippets/csharp/VS_Snippets_CLR_System/system.Threading.ThreadStart2/CS/source2.cs#2)]
3234
[!code-vb[System.Threading.ThreadStart2#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Threading.ThreadStart2/VB/source2.vb#2)]
3335

34-
## Passing Data to Threads and Retrieving Data from Threads
36+
## Passing data to threads
37+
3538
In the .NET Framework version 2.0, the <xref:System.Threading.ParameterizedThreadStart> delegate provides an easy way to pass an object containing data to a thread when you call the <xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType> method overload. See <xref:System.Threading.ParameterizedThreadStart> for a code example.
3639

37-
Using the <xref:System.Threading.ParameterizedThreadStart> delegate is not a type-safe way to pass data, because the <xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType> method overload accepts any object. An alternative is to encapsulate the thread procedure and the data in a helper class and use the <xref:System.Threading.ThreadStart> delegate to execute the thread procedure. This technique is shown in the two code examples that follow.
38-
39-
Neither of these delegates has a return value, because there is no place to return the data from an asynchronous call. To retrieve the results of a thread method, you can use a callback method, as demonstrated in the second code example.
40-
40+
Using the <xref:System.Threading.ParameterizedThreadStart> delegate is not a type-safe way to pass data, because the <xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType> method overload accepts any object. An alternative is to encapsulate the thread procedure and the data in a helper class and use the <xref:System.Threading.ThreadStart> delegate to execute the thread procedure. The following example demonstrates this technique:
41+
4142
[!code-cpp[System.Threading.ThreadStart2#3](../../../samples/snippets/cpp/VS_Snippets_CLR_System/system.Threading.ThreadStart2/CPP/source3.cpp#3)]
4243
[!code-csharp[System.Threading.ThreadStart2#3](../../../samples/snippets/csharp/VS_Snippets_CLR_System/system.Threading.ThreadStart2/CS/source3.cs#3)]
4344
[!code-vb[System.Threading.ThreadStart2#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Threading.ThreadStart2/VB/source3.vb#3)]
45+
46+
Neither <xref:System.Threading.ThreadStart> nor <xref:System.Threading.ParameterizedThreadStart> delegate has a return value, because there is no place to return the data from an asynchronous call. To retrieve the results of a thread method, you can use a callback method, as shown in the next section.
4447

45-
### Retrieving Data with Callback Methods
48+
## Retrieving data from threads with callback methods
49+
4650
The following example demonstrates a callback method that retrieves data from a thread. The constructor for the class that contains the data and the thread method also accepts a delegate representing the callback method; before the thread method ends, it invokes the callback delegate.
4751

4852
[!code-cpp[System.Threading.ThreadStart2#4](../../../samples/snippets/cpp/VS_Snippets_CLR_System/system.Threading.ThreadStart2/CPP/source4.cpp#4)]
4953
[!code-csharp[System.Threading.ThreadStart2#4](../../../samples/snippets/csharp/VS_Snippets_CLR_System/system.Threading.ThreadStart2/CS/source4.cs#4)]
5054
[!code-vb[System.Threading.ThreadStart2#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Threading.ThreadStart2/VB/source4.vb#4)]
5155

52-
## See Also
56+
## See also
57+
5358
<xref:System.Threading.Thread>
5459
<xref:System.Threading.ThreadStart>
5560
<xref:System.Threading.ParameterizedThreadStart>
5661
<xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType>
57-
[Threading](../../../docs/standard/threading/index.md)
58-
[Using Threads and Threading](../../../docs/standard/threading/using-threads-and-threading.md)
62+
[Threading](index.md)
63+
[Using Threads and Threading](using-threads-and-threading.md)

docs/visual-basic/programming-guide/concepts/threading/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Threading enables your Visual Basic program to perform concurrent processing so
3232
|Title|Description|
3333
|-----------|-----------------|
3434
|[Multithreaded Applications (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/multithreaded-applications.md)|Describes how to create and use threads.|
35-
|[Parameters and Return Values for Multithreaded Procedures (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md)|Describes how to pass and return parameters with multithreaded applications.|
3635
|[Thread Synchronization (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-synchronization.md)|Describes how to control the interactions of threads.|
3736
|[Thread Pooling (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-pooling.md)|Describes how to use a pool of worker threads that are managed by the system.|
3837
|[How to: Use a Thread Pool (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/how-to-use-a-thread-pool.md)|Demonstrates synchronized use of multiple threads in the thread pool.|

docs/visual-basic/programming-guide/concepts/threading/multithreaded-applications.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,4 @@ newThread.Abort()
6969
## See Also
7070
<xref:System.Threading.Thread>
7171
[Thread Synchronization (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/thread-synchronization.md)
72-
[Parameters and Return Values for Multithreaded Procedures (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/parameters-and-return-values-for-multithreaded-procedures.md)
7372
[Threading (Visual Basic)](../../../../visual-basic/programming-guide/concepts/threading/index.md)

0 commit comments

Comments
 (0)