Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:18:55+00:00 2026-05-28T18:18:55+00:00

I’m trying to use the iCarousel library in monotouch. I successfully ported the library,

  • 0

I’m trying to use the iCarousel library in monotouch. I successfully ported the library, everything works perfectly but the application crashes if you enter too many UIImageViews with images inside, which is normal because iCarousel is just like a UIScrollView.

I definitely have to use lazy loading system somehow from a secondary thread and display only 3-4 images at once but I do not know how to make this work smooth.

At this point, I set this in the iCarousel Delegate:

bool threadsAlive = true; 

public cDelegate() 
{ 
    ThreadPool.QueueUserWorkItem( delegate { refresh_visible(); } ); 
} 

public override void DidScroll (iCarousel carousel) 
{ 
        scrolling = true; 
} 

public override void DidEndScrollingAnimation (iCarousel carousel) 
{ 
        scrolling = false;  
        //show images that are currently on the screen 
        ThreadPool.QueueUserWorkItem( delegate { ShowCurrent();         } ); 
        //hides images that are not on the screen         
        ThreadPool.QueueUserWorkItem( delegate { hideInvisibleImages(); } ); 
} 

void refresh_visible() 
{ 
        while( threadsAlive ) 
        { 
                while( scrolling ) 
                { 
                        ShowCurrent(); 
                } 
        } 
} 

void refresh_hidden() 
{ 
        while( threadsAlive ) 
        { 
                while( scrolling ) 
                { 
                        hideInvisibleImages(); 
                } 
        } 
} 

public void ShowCurrent() 
{ 
        var          ds = _carousel.DataSource as cDataSource; 
        var left_index  = _carousel.CurrentItemIndex - 1; 
        var right_index = _carousel.CurrentItemIndex + 2; 
        if( left_index  <  0 ) left_index  = 0; 
        if( right_index >= ds.Lista.Count ) right_index = ds.Lista.Count - 1; 
        // 
        for( var i = left_index; i < right_index ; i++ ) 
        { 
                var img = ds.Lista[i]; 
                if( img.Image == null ) 
                { 
                        BeginInvokeOnMainThread( delegate{ 
                                img.Image = UIImage.FromFile( img.UserObject.ToString() ); 
                        }); 
                } 
        } 
} 


void hideInvisibleImages() 
{ 
        Console.WriteLine("ascund!"); 
        var          ds = _carousel.DataSource as cDataSource; 
        var left_index  = _carousel.CurrentItemIndex - 1; 
        var right_index = _carousel.CurrentItemIndex + 2; 
        if( left_index  <  0 ) left_index  = 0; 
        if( right_index >= ds.Lista.Count ) right_index = ds.Lista.Count - 1; 
        // 
        for( var i=0; i<left_index; i++ ) 
        { 
                var img   = ds.Lista[i]; 
                if( img.Image != null ) 
                { 
                        img.Image.Dispose(); 
                        img.Image = null; 
                } 
        } 
        for( var i=right_index; i<ds.Lista.Count; i++ ) 
        { 
                var img   = ds.Lista[i]; 
                if( img.Image != null ) 
                { 
                        img.Image.Dispose(); 
                        img.Image = null; 
                } 
        } 
} 

The code is actually very simple: there is a main thread that only shows 1 image from the left of the current index and two images in advance, and another thread that cleans all other images, hides them.

It’s working, memory is ok, but it’s not smooth on the device, it “hangs” a little when I scroll. There is another way of doing this ? Or maybe I should change the algoritm?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:18:56+00:00Added an answer on May 28, 2026 at 6:18 pm

    You are having a loop that won’t allow CPU to any other thread/process and will lead to a very high CPU utilization. This is making it hang when you scroll.

    Try using Thread.Sleep(1) or a small sleep time in the refresh_visible method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.