0

Possible Duplicate:
simulate cpu usage in mono for Android

Is there any other way to use more cpu rather than threading in mono/android application? please give some suggestion.

Thanks,

Community
  • 1
  • 1
wbi
  • 40
  • 2
  • 4
  • Is there any reason as to why you did not update your existing thread? http://stackoverflow.com/questions/10910663/simulate-cpu-usage-in-mono-for-android – Cheesebaron Jun 21 '12 at 13:27

3 Answers3

0

what a bizarre question. You can do all sorts of processor intensive things in the main thread. Read and write bitmap data, perform all sorts of calculations, etc. Why would you want to do this? And how much of the CPU are you hoping to tie up?

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
  • I need to develop an application to hog more cpu as much i configured like 30%,60%,70%.I did this using threaing concept is there any other way apart from threading? – wbi Jun 21 '12 at 07:55
  • Why do you need to avoid threading? – Yevgeny Simkin Jun 21 '12 at 07:57
  • I dnt want to use threads in my app,I need to use some other technic to use cpu.I wanted to know is there any other thing that act as a threading? can we do ? – wbi Jun 21 '12 at 08:06
  • 1
    I don't think avoiding using threads will work. How do you suppose to allow all CPU kernels being loaded if you cannot launch things in parallel? – Cheesebaron Jun 21 '12 at 13:19
0

No idea what pupose it serves, but this doesn't use any worker threads and will suck up CPU pretty well:

[Activity(MainLauncher = true)]
public class PointlessActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        while(true) { }
    }
}
ctacke
  • 66,480
  • 18
  • 94
  • 155
  • That will load one thread. So running this on a multi-core Android device will only load 1/number of cores. – Cheesebaron Jun 21 '12 at 13:21
  • Yes, but the "without threading" requirement of the OP is pretty limiting. The same will be true for anything you try without threads. – ctacke Jun 21 '12 at 13:28
0

You can implement a Canvas which invalidates everyTime like this:

private class Painter extends View{
        ArrayList<Point> points;
    public Painter(Context context){
        super(context);
    }

    public void draw() {
    points = new ArrayList<Point();

            for (int i = 0; i < 10000; i++) {
                //assign Points to the array
                Point p = new Point();
                p.x = 10;
                p.y = 30;
                points.add(p);
            }
            nameOfTheInstancePainter.invalidate();
    }

    @Override 
    protected void onDraw(Canvas c) {
        for (int i = 0; i < 10000; i++) {
                //paint aaaall the points
            }
        nameOfTheInstancePainter.invalidate(); //that will cause the ReDraw of everything everytime
    }
}

Oh, by the way, painting a canvas use different threads, that's why I did this code !

Miquel Coll
  • 759
  • 15
  • 49