I am trying to access a C # .Net dll from python and print the status in python when executing C # methods. Please help me solve this problem. I tried under the code:
C # dll Class Library Contains Window Shape Control
using System;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
namespace TestLib
{
public partial class TestForm : Form
{
public TestForm()
{
InitializeComponent();
}
public string Method()
{
try
{
Task task = Task.Factory.StartNew(() => Interact_With_Python());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return "Forms Says Hello";
}
private void Interact_With_Python()
{
PrintStatus("Hello World...");
Thread.Sleep(1000);
PrintStatus("Hello World...1");
Thread.Sleep(1000);
PrintStatus("Hello World...2");
Thread.Sleep(1000);
}
private delegate void UpdateStatusDelegate(string status);
private void PrintStatus(string status)
{
if (this.richTextBox.InvokeRequired)
{
this.Invoke(new UpdateStatusDelegate(this.PrintStatus), new object[] { status });
return;
}
this.richTextBox.AppendText(status);
}
}
}
Python: calling methods from C # dll
import clr
from types import *
from System import Action
clr.AddReference("C:\..\TestLib.dll")
import TestLib
form = TestLib.TestForm()
form.Show()
val = form.Method()
print(val)
source
share