Run time error using wait_modified?

class ahb_env extends uvm_env;
...
ahb_agent agent1_h;
...
	virtual task main_phase(uvm_phase phase);
	
		for (int i=0; i < 5; i++) begin 

			uvm_config_db #(int)::set (this, "agent1_h", "loopCount", i);

		end 


	endtask
endclass
class ahb_agent extends uvm_agent;
...
       virtual task run_phase(uvm_phase phase);
	
		if (uvm_config_db#(int)::wait_modified(this, "", "loopcount"))  // this is line 59

			`uvm_info(get_type_name(), $psprintf("getting i value after waiting, loopcount = %0d", i), UVM_LOW);
	
		
	endtask
endclass

I get the following error:

** Error: (vsim-8220) ahb_agent.sv(59): This or another usage of ‘<class-spec#743>::wait_modified’ inconsistent with ‘task’ object.

Region: /file_list_svh_unit

** Error: (vsim-8220) ahb_agent.sv(59): This or another usage of ‘<class-spec#743>::wait_modified.$$’ inconsistent with ‘(null)’ object.

Region: /file_list_svh_unit

Error loading design

How to resolve the errors? Thank you.

In reply to rakesh2learn:

wait_modified() is a task it does not return any values, and it’ll block until new configuration settings are applied for the field. So, it cannot be used inside if condition.