问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
public class TextViewnew : TextView
{
//在应用层或者领域层的某个方法 MethodA() 对 A 表进行了增删改查操作,
// 同时在 领域事件EventHanlderA 中绑定了A表的增删改查对应的领域事件,
// 如果在MethodA方法和领域事件中用到了一个相同的领域服务DomainServiceA,
// 这种场景下MethodA中的方法可以正常执行,但是领域事件中就会因为DomainServiceA已被释放而提示异常:
// 具体原因和ABP的架构有关系
public TextViewnew(Context? context): base(IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
{
if (!(base.Handle != IntPtr.Zero))
{
try
{
}
finally
{
GC.KeepAlive(context);
}
}
}
public int sroke_width = 1;
protected override void OnDraw(Canvas canvas)
{
Paint paint = new Paint();
// 将边框设为黑色
// 画TextView的4个边
paint.Color = Color.Black;
canvas.DrawLine(0, 0, this.Width - sroke_width, 0, paint);
canvas.DrawLine(0, 0, 0, this.Height - sroke_width, paint);
canvas.DrawLine(this.Width - sroke_width, 0, this.Width - sroke_width, this.Height - sroke_width, paint);
canvas.DrawLine(0, this.Height - sroke_width, this.Width- sroke_width, this.Width - sroke_width, paint);
base.OnDraw(canvas);
}
}
```c#
```c#
TextViewnew txs22;
txs22 = new TextViewnew(this);
txs22.SetText("123", TextView.BufferType.Normal);
tableRow.AddView(txs22);
###### 运行结果及报错内容
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'App_jxgl.TextViewnew'.'
###### 我的解答思路和尝试过的方法
###### 我想要达到的结果
安卓自定义控件如何实现还需要哪里步骤