discord-rpc-csharp
discord-rpc-csharp copied to clipboard
[BUG] The current state of DiscordRpcClient.Deinitialize
What actually is the purpose of Deinitialize
?
I'm working on a small utility tool that uses this library and i wanted to be able to easily activate/deactivate the rpc client which i thought was the purpose of Deinitialize
but after calling it u cant do anything cause the namedPipe gets disposed and the thread is not being nulled which makes calling Initialize
again impossible
Is this still the case, are you unable to recall Initialize after calling Deinitialize. If so, please reopen this issue as that is a bug. The purpose of deinitialize was to clear the RPC connection but retain all the configuration for it, so you could later call Initialize again
This seems still be the case on the main branch here, i temp fixed it on my fork for now
What i did was change the 2 main reasons Initialize
cannot be called again
-
move the disposal of the named pipe from here into the
Dispose()
method https://github.com/Lachee/discord-rpc-csharp/blob/6f94c2be7b1e3c69ad12b7bf2ab97955c2accf98/DiscordRPC/RPC/RpcConnection.cs#L446-L447 -
call
thread.join()
to wait for the thread to finish & null it afterwards while also resettingaborted
to false afterwards callingthread.join()
has the slight negative effect that it locks the calling thread while the worker thread finishes its work https://github.com/Lachee/discord-rpc-csharp/blob/6f94c2be7b1e3c69ad12b7bf2ab97955c2accf98/DiscordRPC/RPC/RpcConnection.cs#L830-L833
i also invoked the OnClose
event in Deinitialize
to know when the shutdown completed cause it seemed weird that there is no event indicating that and i didnt wanna check IsInitialized
in a loop
if (OnClose != null)
OnClose.Invoke(this, new CloseMessage("Manual shutdown request"));
Also sry for opening 2 issues, couldnt remove the label here and wasnt sure if its a bug so i closed & reopened another one without a label