Creating Threads
3 posts
• Page 1 of 1
Creating Threads
I'm trying to create a new thread but without much success so far. There are a few examples where System.Threading is used to let the application sleep but I couldn't find anything about creating threads.
Here are parts of the code, first the worker class:
which is supposed to be used by this code:
Using $worker->ProcessRequest as a parameter in the Thread class doesn't do anything good.
I get this error on the console before the process crashes:
I also tried to use a call by reference but that didn't work either.
I'm working with 3.0.0.3237 by the way.
Any ideas on how to get this running?
Here are parts of the code, first the worker class:
- Code: Select all
class Worker
{
public function ProcessRequest()
which is supposed to be used by this code:
- Code: Select all
$worker = new Worker($obj);
$thread = new \System\Threading\Thread($worker->ProcessRequest);
$thread->Start();
Using $worker->ProcessRequest as a parameter in the Thread class doesn't do anything good.
I get this error on the console before the process crashes:
Unhandled Exception: PHP.Core.PhpNetInternalException: Guarded call ---> System.ArgumentNullException: Value cannot be null.
I also tried to use a call by reference but that didn't work either.
I'm working with 3.0.0.3237 by the way.
Any ideas on how to get this running?
- Remo
- Posts: 17
- Joined: August 17th, 2012, 3:25 pm
Re: Creating Threads
Hi,
Phalanger defines its own function for creating new threads, so you can create them in PHP-like way.
Try to use
Otherwise in your sample, you are mixing C# syntax with PHP syntax. In PHP you can't create callbacks by passing method without arguments. You have to pass function name as a string or an array(class name or instance, method name). Something like this
But I don't believe Phalanger will properly convert PHP array to C# System.Action ...
Phalanger defines its own function for creating new threads, so you can create them in PHP-like way.
Try to use
- Code: Select all
clr_create_thread(callback, arguments);
Otherwise in your sample, you are mixing C# syntax with PHP syntax. In PHP you can't create callbacks by passing method without arguments. You have to pass function name as a string or an array(class name or instance, method name). Something like this
- Code: Select all
new \System\Threading\Thread(array($worker,"ProcessRequest"));
But I don't believe Phalanger will properly convert PHP array to C# System.Action ...
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Creating Threads
Thanks Jakub!
I think it does cast that array to a proper object in .NET. My code still has a problem but I'm pretty sure the thread is created. I'll work on the next problem and see where it goes
I think it does cast that array to a proper object in .NET. My code still has a problem but I'm pretty sure the thread is created. I'll work on the next problem and see where it goes
- Remo
- Posts: 17
- Joined: August 17th, 2012, 3:25 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 14 guests