我想删除警告:"将此替换为具有强身份的对象的锁定"

Har*_*Boy 3 .net c# com

我有一个ActiveX COM对象,用于播放视频及其在C#应用程序中使用.声明如下:

private AxVIDEOPLAYERUILib.AxVideoPlayerUI axVideoPlayerUI;
Run Code Online (Sandbox Code Playgroud)

在我的代码中有锁定就像这样:

lock (axVideoPlayerUI)
{
     axVideoPlayerUI.EnableControls = 1;
     axVideoPlayerUI.Visible = true;
     axVideoPlayerUI.ShowOverlay = 1;
     axVideoPlayerUI.OverlayPosition = 3;
     axVideoPlayerUI.Play();         
 }
Run Code Online (Sandbox Code Playgroud)

但我得到警告,我想摆脱:

警告1 CA2002:Microsoft.Reliability:'VideoPlayerControl.LoadRecording(RecordVideo,int)'锁定'AxVideoPlayerUI'类型的引用.将其替换为具有强身份的对象的锁定.

从此链接http://msdn.microsoft.com/en-us/library/ms182290.aspx它指出以下对象具有弱标识:

MarshalByRefObject,ExecutionEngineException,OutOfMemoryException,StackOverflowException,String,MemberInfo,ParameterInfo,Thread.

但我的目标不属于任何这些类别.

我也试过让我的对象静态,如下所述:C#lock和代码分析警告CA2002,但这给了我错误:

错误1无法使用实例引用访问成员"MyNameSpace.VideoPlayerControl.axVideoPlayerUI"; 用类型名称来限定它

有谁知道我怎么能摆脱原来的警告?

Dam*_*ver 6

您可以声明一个单独的对象用于锁定:

private AxVIDEOPLAYERUILib.AxVideoPlayerUI axVideoPlayerUI;
private object axVideoPlayerUILock = new object();
Run Code Online (Sandbox Code Playgroud)

和:

lock (axVideoPlayerUILock)
{
   ...
Run Code Online (Sandbox Code Playgroud)

COM代理是由实现的System.__ComObject,而后者又来源于MarshalByRefObject.也许指导可以更清楚的是,从提到的那些类型衍生的类型也是不可用的.