CallContext.FreeNamedDataSlot(String) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Vide un emplacement de données portant le nom spécifié.
public:
static void FreeNamedDataSlot(System::String ^ name);
public static void FreeNamedDataSlot (string name);
[System.Security.SecurityCritical]
public static void FreeNamedDataSlot (string name);
static member FreeNamedDataSlot : string -> unit
[<System.Security.SecurityCritical>]
static member FreeNamedDataSlot : string -> unit
Public Shared Sub FreeNamedDataSlot (name As String)
Paramètres
- name
- String
Nom de l'emplacement de données à vider.
- Attributs
Exceptions
L'appelant immédiat n'a pas d'autorisation d'accès à l'infrastructure.
Exemples
L’exemple de code suivant montre un client qui crée un emplacement de données nommé, appelle une méthode sur l’objet distant qui affiche la valeur de l’emplacement de données nommé retourné à partir du thread logique et libère cet emplacement de données nommé.
// Register the channel.
TcpChannel^ myChannel = gcnew TcpChannel;
ChannelServices::RegisterChannel( myChannel );
RemotingConfiguration::RegisterActivatedClientType( HelloService::typeid, "Tcp://localhost:8082" );
GenericIdentity^ myIdentity = gcnew GenericIdentity( "Bob" );
array<String^>^ idStr = gcnew array<String^>(1);
idStr[ 0 ] = "Level1";
GenericPrincipal^ myPrincipal = gcnew GenericPrincipal( myIdentity, idStr );
MyLogicalCallContextData ^ myData = gcnew MyLogicalCallContextData( myPrincipal );
// Set DataSlot with name parameter.
CallContext::SetData( "test data", myData );
// Create a remote Object*.
HelloService ^ myService = gcnew HelloService;
if ( myService == nullptr )
{
Console::WriteLine( "Cannot locate server." );
return -1;
}
// Call the Remote methods.
Console::WriteLine( "Remote method output is {0}", myService->HelloMethod( "Microsoft" ) );
MyLogicalCallContextData ^ myReturnData =
(MyLogicalCallContextData^)( CallContext::GetData( "test data" ) );
if ( myReturnData == nullptr )
{
Console::WriteLine( "Data is 0." );
}
else
{
Console::WriteLine( "Data is ' {0}'", myReturnData->numOfAccesses );
}
// DataSlot with same Name Parameter which was Set is Freed.
CallContext::FreeNamedDataSlot( "test data" );
MyLogicalCallContextData ^ myReturnData1 =
(MyLogicalCallContextData^)( CallContext::GetData( "test data" ) );
if ( myReturnData1 == nullptr )
{
Console::WriteLine( "FreeNamedDataSlot Successful for test data" );
}
else
{
Console::WriteLine( "FreeNamedDataSlot Failed for test data" );
}
// Register the channel.
TcpChannel myChannel = new TcpChannel ();
ChannelServices.RegisterChannel(myChannel);
RemotingConfiguration.RegisterActivatedClientType(typeof(HelloService),"Tcp://localhost:8082");
GenericIdentity myIdentity = new GenericIdentity("Bob");
GenericPrincipal myPrincipal = new GenericPrincipal(myIdentity,new string[] {"Level1"});
MyLogicalCallContextData myData = new MyLogicalCallContextData(myPrincipal);
// Set DataSlot with name parameter.
CallContext.SetData("test data",myData);
// Create a remote object.
HelloService myService = new HelloService();
if (myService == null)
{
Console.WriteLine("Cannot locate server.");
return;
}
// Call the Remote methods.
Console.WriteLine("Remote method output is " + myService.HelloMethod("Microsoft"));
MyLogicalCallContextData myReturnData =
(MyLogicalCallContextData) CallContext.GetData("test data");
if (myReturnData == null )
Console.WriteLine("Data is null.");
else
Console.WriteLine("Data is '{0}'", myReturnData.numOfAccesses);
// DataSlot with same Name Parameter which was Set is Freed.
CallContext.FreeNamedDataSlot("test data");
MyLogicalCallContextData myReturnData1 =
(MyLogicalCallContextData) CallContext.GetData("test data");
if (myReturnData1 == null )
Console.WriteLine("FreeNamedDataSlot Successful for test data");
else
Console.WriteLine("FreeNamedDataSlot Failed for test data");
' Register the channel.
Dim myChannel As New TcpChannel()
ChannelServices.RegisterChannel(myChannel)
RemotingConfiguration.RegisterActivatedClientType(GetType(HelloService), "Tcp://localhost:8082")
Dim myIdentity As New GenericIdentity("Bob")
Dim myPrincipal As New GenericPrincipal(myIdentity, New String() {"Level1"})
Dim myData As New MyLogicalCallContextData(myPrincipal)
' Set DataSlot with name parameter.
CallContext.SetData("test data", myData)
' Create a remote object.
Dim myService As New HelloService()
If myService Is Nothing Then
Console.WriteLine("Cannot locate server.")
return
End If
' Call the Remote methods.
Console.WriteLine("Remote method output is " + myService.HelloMethod("Microsoft"))
Dim myReturnData As MyLogicalCallContextData = _
CType(CallContext.GetData("test data"), MyLogicalCallContextData)
If myReturnData Is Nothing Then
Console.WriteLine("Data is null.")
Else
Console.WriteLine("Data is '{0}'", myReturnData.numOfAccesses)
End If
' DataSlot with same Name Parameter which was Set is Freed.
CallContext.FreeNamedDataSlot("test data")
Dim myReturnData1 As MyLogicalCallContextData = _
CType(CallContext.GetData("test data"), MyLogicalCallContextData)
If myReturnData1 Is Nothing Then
Console.WriteLine("FreeNamedDataSlot Successful for test data")
Else
Console.WriteLine("FreeNamedDataSlot Failed for test data")
End If