Main Site Documentation

Task and TaskScheduler


#1

Just a note that I put up a Task library on Fezzer.com. Modeled after Task in .Net. If in need of thread pool and tasks, now have on MF. Should be able to really heat those Fez boards. hth
http://www.fezzer.com/#do=recentProjects&page=1


#2

Hi William,

I’m trying out your TaskScheduler code and can’t get past a reference error on System.Environment.Tickcount. The object browser also can’t navigate to this class. Any idea what I might try to see this class.

Thx


#3

For future, the correct link is http://code.tinyclr.com/project/206/task-and-taskscheduler/


#4

It is System.Environment.TickCount. It is part of the mscorlib.dll it should be there. Try to remove the reference and add it again.


#5

I’ve tried both uninstalling and reinstalling the 4.1 SDK as well removing the reference but I just can’t get past this compile error. Very weird.

Anyone ever sen any issues like this that point to an undocumented die bug.

Thx


#6

Found it!

Microsoft.SPOT.Time.dll

http://www.tinyclr.com/forum/1/1533/


#7

Well this either fixed the issue or allowed a new error to surface . Now I can’t compile because of the following error:

Error 1 CLR_E_FAIL c:\users\brent\documents\visual studio 2010\Projects\FEZ Cobra Console Application1\FEZ Cobra Console Application1\MMP FEZ Cobra Console Application1

I’ve never seen this one so I’m at a loss where to start looking. It’s definitily a bug in the task-and-taskscheduler.cs file because with a new project that only includes this file plus the correct references I get the error above.


#8

BTW what .net architect was asleep at the wheel when they put System.Environment.TickCount in the Microsoft.SPOT.Time dll. I’m sure other micro framework noobs like me might just give up before throwing up their arms. I’m a C# dev that has been using the .net platform since day one and I love this platform but this kind of stuff just drives me crazy.

Is there a doc somewhere that lists other such gotchas?

Sorry for venting but this has cost me the whole day. thank goodness for a responsive community.

thx


#9

Does it work now after getting assembly ref?


#10

No the new error now pops up when I try to compile which points to some unknown bug in the code.

Error 1 CLR_E_FAIL c:\users\brent\documents\visual studio 2010\Projects\FEZ Cobra Console Application1\FEZ Cobra Console Application1\MMP FEZ Cobra Console Application1

Progress though but still no joy.


#11

Show us some code may be we can help.


#12

I just created a new project and added task-and-taskscheduler.cs to the project as well as task-and-taskscheduler_example.cs from the article and try to compile and I get this error.

Also I added the reference to Microsoft.Spot.Time

Here’s the whole project in my Dropbox:
http://dl.dropbox.com/u/15142496/FEZ%20Cobra%20Console%20Application2.zip


#13

I see the issue. It is inside BlockingQueue.GetEnumerator method:


        public IEnumerator GetEnumerator()
        {
            this.CheckDisposed();
            object[] array;
            sync.Enter();
            try
            {
                array = q.ToArray();
            }
            finally
            {
                sync.Exit();
            }

            foreach (object o in array)
            {
                yield return o;
            }
        }

yield is not yet supported in MF. You need to add your own Enumerator, or if you are not using it just comment out last foreach loop and return null.


#14

That did it. Here’s my edit:

public IEnumerator GetEnumerator()
        {
            this.CheckDisposed();
            object[] array;
            sync.Enter();
            try
            {
                array = q.ToArray();
            }
            finally
            {
                sync.Exit();
            }

            //foreach (object o in array)
            //{
            //    yield return o;
            //}
            return null;
        }

I wonder if this code will perform as expected with this change?

Thanks for finding this. much appreciated.


#15

I haven’t checked how BlockingQueue us used. Adding non-yield based enumerator is pretty easy, though. This will ensure that class will work as intended.


#16

I don’t understand why ‘yield’ is not supported and this code has been out in the community for some time. Was William using a beta version of MF?


#17

I guess nobody used it yet. yield is supported by the compiler,but the generated code behind it uses piece of framework, that is not on MF yet.

I let William to answer that one ;D


#18

Maybe I’m even barking up the wrong tree with this code. What I’m trying to build is an irrigation system that can respond to many unknown schedules that operate the I2C relay from GHI. It has 16 relays (zones) and I need to to be able to save the schedules on the SD card and then respond to them as they

  • user sends string via serial to describe a schedule for a specific zone. Turn on relay 7 for 30 minutes every day at 1:00 AM in the months of April to November. The communication protocol I have figured out yet.
  • Schedules are saved to SD card so that they can be retrived on reboots.

William’s Task and Scheduler code was the closest example I could find to get me started.


#19

I forgot my code :-|. Are you saying I used Yield and you can’t compile. Or that I did not use yield when I sould have? I used plain old GHI 4.1 to answer question.

IIRC, yield is not supported as it calls some kind of method with a non-mf supported attribute on it. I think it was a testing oversite they can (and should) fix. That said, I swear I used it a couple times in MF and it worked. Either I mis-remember or the yield can work under certain circumstances that take it down a different logic path - not sure. Can you show me code snip in question. That said, you can step around yield with an IEnumerator imp.


#20

That one.