I need to create a threading functionality in my .net project using Python. For this I have created a console application (C#) and added Python and IronPython references.When I run the multithreading code I am getting following error
IronPython.Runtime.Exceptions.ImportException: 'No module named threading'
Is there any references need to add for Threading? When I googled it i didn't find any reference to add.
Following is the code
import threading
from threading import Thread
def PaymentCalculation(userid):
sum = 1+1
return sum
def ProcessingData():
data = GetAssigneeData() #will return dataset from DB
for member in data.Tables[0].Rows:
pthread = Thread(target=PaymentCalculation, args=(member["UserId"],))
pthread.start()
I solved the issue. I was used normal python code. Its is not IronPython code. I made change code like below.
from System.Threading import (
ApartmentState,
Thread, ThreadStart,ParameterizedThreadStart
)
def PaymentCalculation(userid):
sum = 1+1
return sum
def ProcessingData():
data = GetAssigneeData()
for member in data.Tables[0].Rows:
thread = Thread(ParameterizedThreadStart(PaymentCalculation))
thread.SetApartmentState(ApartmentState.STA)
thread.Start(member["UserId"])