使用" DllImport"在多线程C#应用程序中

时间:2016-04-16 10:08:41

标签: c# c++ multithreading

我有以下代码:

    static void manageThreads(string user, string pass)
    {
        Sessions sess = new Session();
        sess.beginSession(user, pass);
    }

    static void Main(string[] args)
    {
        string user = "blah";
        string pass = "blah";
        int count = 10;
        int initial = 0;

        Thread[] sessions = new Thread[count];
        for (int i = 0; i < count; i++)
        {
            sessions[i] = new Thread(() => manageThreads(user + (i + initial), pass + (i + initial)));
        }

        for (int i = 0; i < count; i++)
        {
            sessions[i].Start();
        }
    }

(我知道这很乱) 但在会话代码中我有以下几点:

    [DllImport("IdlerLib.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int startSession(String user, String pass);

    public void beginSession(string User, string Pass)
    {
        startSession(User, Pass);}

然后传递给用户并传递给启动登录会话的C ++ DLL, 现在的问题是它似乎只在一个线程上调用该函数,是否可以在多个线程上同时运行相同的函数?

非常感谢 詹姆斯

0 个答案:

没有答案