# C extension with progress bar

**URL:** <https://www.ruby-forum.com/t/c-extension-with-progress-bar/176076>\
**Category:** Ruby\
**Created:** [September 24, 2009, 12:30pm UTC](https://www.ruby-forum.com/t/c-extension-with-progress-bar/176076 "2009-09-24T12:30:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@simi](https://www.ruby-forum.com/u/simi)\
**Post date:** [September 24, 2009, 12:30pm UTC](https://www.ruby-forum.com/t/c-extension-with-progress-bar/176076/1 "2009-09-24T12:30:13Z")

</div>

Hi,

I have a ruby extension which shows a progress bar window.

The progress bar shows the progress of a loop in the ruby code.For each  
iteration of the loop I call an extension method that sets the current  
progress through the PBM\_SETPOS message.

The progress bar is actually shown.The problem arises when I want to  
implement a cancel button in the progress window.

While the progress is updating the window becomes unresponsive and  
cancel button click does not work.

I tried to update the progress in C code through a separate thread using  
CreateThread but it does not show the progress at all.

Kindly suggest solution to fix this problem

Thanks in advance and let me know any other details are required.

Simi

---

<div class="post-metadata">

**Author:** ![simi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@simi](https://www.ruby-forum.com/u/simi)\
**Post date:** [September 25, 2009, 2:21pm UTC](https://www.ruby-forum.com/t/c-extension-with-progress-bar/176076/2 "2009-09-25T14:21:15Z")

</div>

Calling function which is implemented purely in C will block it until  
it returns. Maybe there is a way to call some rb\_thread\_shedule  
(written from memory so it could be wrong) which will let other  
threads to run.

–  
Pozdrawiam

Rados³aw Bu³at  
[http://radarek.jogger.pl](http://radarek.jogger.pl) - mój blog

---

<div class="post-metadata">

**Author:** ![simi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@simi](https://www.ruby-forum.com/u/simi)\
**Post date:** [September 25, 2009, 3:53pm UTC](https://www.ruby-forum.com/t/c-extension-with-progress-bar/176076/3 "2009-09-25T15:53:09Z")

</div>

2009/9/24 Simi Lc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> While the progress is updating the window becomes unresponsive and  
> cancel button click does not work.
> 
> I tried to update the progress in C code through a separate thread using  
> CreateThread but it does not show the progress at all.
> 
> Kindly suggest solution to fix this problem
> 
> Thanks in advance and let me know any other details are required.

In general the UI library which you are using for drawing the progress  
bar should provide means for doing this. However, the solution is  
dependent on the library you use, unfortunately.

So the questions are

What you are using to display the progress bar?

Why did you choose this UI, can’t a different library provide it? What  
are the requirements?

Why did you choose to do that in C? Does the library lack ruby  
bindings? Can’t it be loaded through ffi?

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![simi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@simi](https://www.ruby-forum.com/u/simi)\
**Post date:** [September 25, 2009, 11:01pm UTC](https://www.ruby-forum.com/t/c-extension-with-progress-bar/176076/4 "2009-09-25T23:01:04Z")

</div>

Dear Simi,

there is also a progress bar for Ruby here:

[http://jordan.husney.com/archives/software/binary/ruby\_progressbar.tar.gz](http://jordan.husney.com/archives/software/binary/ruby_progressbar.tar.gz)

It basically lets you print a png file, which you might then show  
somewhere.

Maybe this can be of use …

Best regards,

AXel
