diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs new file mode 100644 index 00000000000..bab52102379 --- /dev/null +++ b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs @@ -0,0 +1,25 @@ +// +open System +open System.Reflection + +type Worker() = + inherit MarshalByRefObject() + member _.PrintDomain() = + printfn $"Object is executing in AppDomain \"{AppDomain.CurrentDomain.FriendlyName}\"" + +// Create an ordinary instance in the current AppDomain +let localWorker = Worker() +localWorker.PrintDomain() + +// Create a new application domain, create an instance +// of Worker in the application domain, and execute code +// there. +let ad = AppDomain.CreateDomain "New domain" +let remoteWorker = + ad.CreateInstanceAndUnwrap(typeof.Assembly.FullName, "Worker") :?> Worker +remoteWorker.PrintDomain() + +// This code produces output similar to the following: +// Object is executing in AppDomain "source.exe" +// Object is executing in AppDomain "New domain" +// \ No newline at end of file diff --git a/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/fs.fsproj b/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/fs.fsproj new file mode 100644 index 00000000000..304d2fa939e --- /dev/null +++ b/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net48 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/source.fs b/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/source.fs new file mode 100644 index 00000000000..d8d51947a51 --- /dev/null +++ b/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/source.fs @@ -0,0 +1,17 @@ +open System +open System.Runtime.Remoting.Lifetime +open System.Security.Permissions + +// +type MyClass() = + inherit MarshalByRefObject() + + [] + override _.InitializeLifetimeService() = + let lease = base.InitializeLifetimeService() :?> ILease + if lease.CurrentState = LeaseState.Initial then + lease.InitialLeaseTime <- TimeSpan.FromMinutes 1 + lease.SponsorshipTimeout <- TimeSpan.FromMinutes 2 + lease.RenewOnCallTime <- TimeSpan.FromSeconds 2 + lease +// \ No newline at end of file diff --git a/snippets/fsharp/System/MarshalByRefObject/Overview/fs.fsproj b/snippets/fsharp/System/MarshalByRefObject/Overview/fs.fsproj new file mode 100644 index 00000000000..304d2fa939e --- /dev/null +++ b/snippets/fsharp/System/MarshalByRefObject/Overview/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net48 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/MarshalByRefObject/Overview/source.fs b/snippets/fsharp/System/MarshalByRefObject/Overview/source.fs new file mode 100644 index 00000000000..368e096d1a6 --- /dev/null +++ b/snippets/fsharp/System/MarshalByRefObject/Overview/source.fs @@ -0,0 +1,19 @@ +// +open System +open System.Runtime.Remoting +open System.Security.Permissions + +type TestClass() = + inherit MarshalByRefObject() + +[] +[] +let main _ = + let obj = TestClass() + + RemotingServices.SetObjectUriForMarshal(obj, "testUri") + RemotingServices.Marshal obj |> ignore + + printfn $"{RemotingServices.GetObjectUri obj}" + 0 +// \ No newline at end of file diff --git a/xml/System/MarshalByRefObject.xml b/xml/System/MarshalByRefObject.xml index 165da40ceae..b79b4782d9e 100644 --- a/xml/System/MarshalByRefObject.xml +++ b/xml/System/MarshalByRefObject.xml @@ -75,6 +75,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/CreateInstanceAndUnwrap2/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/CreateInstanceAndUnwrap2/VB/source.vb" id="Snippet1"::: **Example 2** @@ -83,6 +84,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/RemotingServices.SetObjectUriForMarshal/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MarshalByRefObject/Overview/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/MarshalByRefObject/Overview/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/RemotingServices.SetObjectUriForMarshal/VB/source.vb" id="Snippet1"::: ]]> @@ -293,6 +295,7 @@ For more information about lifetime services, see the